Skip to main content
deleted 28 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 237

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 whyWhy is there is a difference and also how I can correct the first snippet to give me the right result?

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?

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. Why is there is a difference and also how I can correct the first snippet to give me the right result?

Tweeted twitter.com/StackUnix/status/1059098099719778305
added 4 characters in body; edited tags
Source Link
jimmij
  • 48.7k
  • 20
  • 136
  • 141

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?

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?

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?

Source Link

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?