当前位置: 技术问答>linux和unix
Shell下字符串匹配问题,谢谢
来源: 互联网 发布时间:2015-06-18
本文导语: 我想判断一个字符串是不是以/mnt开头的,该如何做?谢谢! | if [ $STRING != ${STRING#/mnt} ]; then # do you want fi | ^/mnt ??? 或者 ^/mnt ??? | echo /mnt | awk '...
我想判断一个字符串是不是以/mnt开头的,该如何做?谢谢!
|
if [ $STRING != ${STRING#/mnt} ]; then
# do you want
fi
# do you want
fi
|
^/mnt ???
或者 ^/mnt ???
或者 ^/mnt ???
|
echo /mnt | awk '{if($0~/^/mnt/) print "match"}'
|
fl="/mnt/cdrom/test.sh"
fm="/mns/cdrom/test.sh"
if [ $fl^/mnt/cdrom ];then //careful
echo "matching!"
else
echo "not matching!"
fi
fm="/mns/cdrom/test.sh"
if [ $fl^/mnt/cdrom ];then //careful
echo "matching!"
else
echo "not matching!"
fi
|
用awk