标签:开头 字符串连接 bash 取子串 字符串处理 命令 字符串替换 ash 查找
str="abc"
echo ${#str}
str="abc" str1=`expr index $str "a"` echo $str1
str="abc" str1=`expr substr $str 1 2` echo $str1
str="abcdef"
echo ${str:2} # 从第二个位置开始提取字符串, bcdef
echo ${str:2:3} # 从第二个位置开始提取3个字符, bcd
echo ${str:(-6):5} # 从倒数第二个位置向左提取字符串, abcde
echo ${str:(-4):3} # 从倒数第二个位置向左提取6个字符, cde
str="apple, tree, apple tree"
echo ${str/apple/APPLE} # 替换第一次出现的apple
echo ${str//apple/APPLE} # 替换所有apple
echo ${str/#apple/APPLE} # 如果字符串str以apple开头,则用APPLE替换它
echo ${str/%apple/APPLE} # 如果字符串str以apple结尾,则用APPLE替换它
str="abc"
str1="ab"
str2=${str}${str1}
标签:开头 字符串连接 bash 取子串 字符串处理 命令 字符串替换 ash 查找
原文地址:http://www.cnblogs.com/dmir/p/6267374.html