1

I tried to negate the following condition:

if pgrep "$NAME" >> /dev/null; then
    # stuff
fi

At first I tried a syntax, what you can found in this thread.

if ! [[ pgrep "$NAME" >> /dev/null ]]; then
    # stuff
fi

While this syntax is perfect if you want to compare variables and literals, however in my case it will fail with the following error:

watchdog: line 58: conditional binary operator expected

watchdog: line 58: syntax error near `"$NAME"'

watchdog: line 58: ` if ! [[ pgrep "$NAME" >> /dev/null ]]; then'

Community
  • 1
  • 1
atevm
  • 801
  • 1
  • 14
  • 27

1 Answers1

3

Simply use ! to to check if it failed:

if ! pgrep "$NAME" >> /dev/null; then
    # stuff
fi
P.P
  • 117,907
  • 20
  • 175
  • 238