shell 查找字符串中字符出现的位置

 

#!/bin/bash
a="The cat sat on the mat"
test="cat"
awk -v a="$a" -v b="$test" 'BEGIN{print index(a,b)}'

输出

bogon:Desktop macname$ ./test.sh 
5

 

 

参考:

 

posted @ 2019-08-23 22:40  anobscureretreat  阅读(5582)  评论(0)    收藏  举报