Skip to main content
2 of 3
added 4 characters in body; edited tags
jimmij
  • 48.7k
  • 20
  • 136
  • 141

Running a Test with expression in a string

I am trying to run the test command from a string. The string contains the expression.

 TEST="! -e ~/bin/xyz"
 if [ `echo "$TEST"` ]; then
    echo running "$TEST";
 fi

However, the above if condition does evaluate to true but if I plug in the command directly (as below), it evaluates to false.

 if [ ! -e ~/bin/xyz ]; then
    echo running;
 fi

The second snippet's behavior is correct. Can someone help me understand why there is a difference and also how I can correct the first snippet to give me the right result?