First, there is no reason to wrap the pgrep command in anything. Just use its exit status:
pgrep -f "$regex" && return 1 || return 0.
If pgrep succeeds, you will return 1; otherwise, you return 0. However, all you do is change the expected exit codes. What you probably want to do is just let pgrep be the last statement of your function; then the pgrep exit code will be the exit code of your function.
something () { ... regex="someWord.*$1.*$2" echo "$regex" pgrep -f $regex }
chepner
source share