我試圖找到包含「someWord」一詞以及其他兩項由$ 1和$ 2p纖ep -f使用多個參數
7 regex="someWord.*$1.*$2"
8 echo "$regex"
9 [ `pgrep -f $regex` ] && return 1 || return 0
返回
./test.sh foo bar
someWord.*foo bar.*
./test.sh: line 9: [: too many arguments
發生什麼代表的具體過程我的正則表達式?直接在shell中執行pgrep可以正常工作。
這可能是真的,我會測試,但不是我的正則表達式阻礙,因爲它顯示「someWord 。* foo bar。*「但應該是」someWord。* foo。* bar「? – tommsen 2013-02-12 17:06:02
它看起來像$ 1被設置爲「foo bar」,而$ 2沒有被設置。你可以在問題中添加更多的'test.sh'嗎? – chepner 2013-02-12 18:14:11