美文网首页
Bash超级会 - 8.字符串 String

Bash超级会 - 8.字符串 String

作者: etfolin | 来源:发表于2022-04-03 23:59 被阅读0次

字符串也是必须有的。

字符串的长度

bash script 获取字符串长度的方法是如此的简单直接而耐人寻味。

#!/bin/bash
Str="Welcome to fosslinux.com"
echo "Length is: ${#Str}"

连接字符串

这才叫简单直接。

#!/bin/bash

string1="foss"
string2="linux.com"
string=$string1$string2
echo "$string is a great website."

截取不叫截取而叫Extracting

#!/bin/bash
Str="Welcome to the fosslinux.com"
# Extracting string from index 15
echo ${Str:15} 
# Extracting string from index 15 of length 5
echo ${Str:15:5}

相关文章

网友评论

      本文标题:Bash超级会 - 8.字符串 String

      本文链接:https://www.haomeiwen.com/subject/apbhnktx.html