Yeah, the "ps | grep | grep -v grep" pattern is silly, there are a few better ways. In this case just:
old_pids=$(pgrep '^haproxy') old_pids=$(pgrep '^haproxy')I see this usage often where it seems like
grep pattern1 | grep -v pattern2
can be replaced by sed -n '/pattern1/d;/pattern2/p'
or at least sed '/pattern1/!d' | sed '/pattern2/d'
or sed -n 's/pattern1pattern2//g;/pattern2/p'
But I must be missing something obvious.For example look at the "grep -v" usage here:
https://github.com/thomwiggers/qhasm/raw/master/qhasm-arm
Is there something wrong with using
sed '/^op:livefloat80:/d'
Moreover, in the last line, why not use sed 's/\$/#/g'
instead of tr '$' '#'
Apologies if I am missing the obvious. grep [h]aproxy