shell中的字符串操作——字符串的切割

default.yaml

{default_baseurl: 'http://10.113.10.68:8082'}

test.sh

a=`cat default.yaml`
t=":"
index=`awk -v a="$a" -v b=":" 'BEGIN{print index(a,b)}'`
diff=${#a}-$index-2
let index=index+1
default_url=`echo ${a:$index:$diff}|sed $'s/\'//g'`
echo $default_url

输出

bogon:conf macname$ ./test.sh 
http://10.113.10.68:8082

参考:

https://www.cnblogs.com/chengmo/archive/2010/10/02/1841355.html

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/11403153.html