您的位置:首页 > 运维架构 > Shell

shell字符串索引

2017-02-01 19:49 507 查看
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


输出如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: