为什么第一个和第二个变体不能工作,但第三个可以工作
#!/bin/sh
#---------------------------------------------
text="my:?text=this:one"
if (echo $text | grep '^my\:\?text=this\:one') then
echo "1"
elif (echo $text | grep '^my:\?text=this:one') then
echo "2"
elif (echo $text | grep 'text=this:one') then
echo "3"
fi发布于 2012-08-21 20:23:40
grep默认情况下不使用正则表达式,请添加-E标志以启用扩展正则表达式。
egrep:grep默认情况下不使用扩展正则表达式,为了更快地使用,通常将grep -E别名为grep
发布于 2012-08-21 20:25:17
将Egrep用于扩展的grep功能:
echo $text | egrep '^my\:\?text=this\:one'发布于 2012-08-21 20:23:12
因为:不是正则表达式中的特殊符号,不需要转义。
https://stackoverflow.com/questions/12054691
复制相似问题