开发者

UNIX "no match" error?

I'm trying to run the following:

  x=$(echo "$1" | egrep -c "^[0-9]|[:&^]")

Now, this code is supposed to look for a word th开发者_StackOverflow中文版at starts with a number, or contains a :,& or ^. However,I geta "no match" error when I run this in UNIX. What makes matters more cofusing is that something similar runs well in terminal, but not in a script.


try this

echo "$1" | nawk '{for(i=1;i<=NF;i++){ if($i ~/^[0-9]|[:&^]/ ){c++;}}}END{ print "count:"c}'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜