Shell使用${}字符串处理
[root@localhost ~]# var=12345678 //字符串长度 [root@localhost ~]# echo ${#var} 8 //截取字符串 ${parameter:offset} ${parameter:offset:length} [root@localhost ~]# echo ${var:4} 5678 [root@localhost ~]# echo ${var:4:2} 56 [root@localhost ~]# echo ${var:(-3):(-1)} 67 //替换字符串 格式:${parameter/pattern/string} [root@localhost ~]# echo ${var/123/888} 88845678 [root@localhost ~]# test="hello world world" [root@localhost ~]# [root@localhost ~]# echo ${test/world/} hello world [root@localhost ~]# echo ${test//world/} //patterm前面开头一个正斜杠为只匹配第一个字符串,两个正斜杠为匹配所有字符。 hello //字符串截取 ${parameter#word} # 删除匹配前缀 ${parameter#