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

输出如下:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM