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

输出如下:

posted @ 2017-02-01 19:49  Sawyer Ford  阅读(4267)  评论(0编辑  收藏  举报