1

I'm trying to run [ pgrep mongo | wc -l -gt 2] to see if there are more than 2 mongo processes running, but I keep getting this error -bash: [: missing `]'

I feel like I'm missing something simple here. Thanks!

Shail Patel
  • 1,764
  • 5
  • 30
  • 46

2 Answers2

2

You need command substitution and a space before ]:

[ $(pgrep mongo | wc -l) -gt 2 ]

$(...) is the syntax for command substitution

anubhava
  • 761,203
  • 64
  • 569
  • 643
1

Besides using command substitution, it is a good idea to use arithmetic expression in that case:

(( $(pgrep mongo | wc -l) > 2 ))
Aleks-Daniel Jakimenko-A.
  • 10,335
  • 3
  • 41
  • 39