bash脚本截取字符串的两种方法(shell截取字符串substr)满满干货

随心笔谈9个月前发布 admin
58 0

#bin/bash
STR=”1234567890asdfghjkl”
echo “first character ${STR:0:1}”
echo “The three characters ${STR:0:3}”
echo “第四个字符开始显示:${STR:3}”
echo “显示第4到6个字符:${STR:3:3}”
echo “显示最后1个字符:${STR:0-1}”
echo “显示最后3个字符:${STR:0-3}”
echo “从右边数第7个,取3个字符${STR:0-7:3}”

© 版权声明

相关文章