shell字符串索引
shell中的字符串索引一会从0开始,一会从1开始,见例子:
#!/bin/bash string="hello world" length=${#string} echo "string is \""$string"\"" echo "length is $length" index=`expr index "$string" 'o'` echo "index of 'o' is $index" substring=${string:$index} echo "substring begins from index $index is \""$substring"\"" echo "shit happens" echo exit 0
输出如下: