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
輸出如下: