Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pgrep -f with multiple arguments

i try to find a specific process containing the term "someWord" and two other terms represented by $1 and $2

 7   regex="someWord.*$1.*$2"
 8   echo "$regex"
 9   [ `pgrep -f $regex` ] && return 1 || return 0

which returns

./test.sh foo bar
someWord.*foo bar.*
./test.sh: line 9: [: too many arguments

What happens to my regular expression? Doing that pgrep directly in the shell works fine.

like image 415
tommsen Avatar asked Feb 12 '13 16:02

tommsen


1 Answers

Good sir, perhaps this

[[ `pgrep -f "$regex"` ]] && return 1 || return 0

or this

[ "`pgrep -f '$regex'`" ] && return 1 || return 0
like image 171
Zombo Avatar answered Oct 17 '22 12:10

Zombo