Hello,

I'm not sure if the behavior below is expected or perhaps a bug?
I'm using GNU coreutils 9.6

According to the TEST(1) manpage:

       -n STRING
              the length of STRING is nonzero

       STRING equivalent to -n STRING


However, the small script below will produce inconsistent results, where
only the first if conditional will evaluate to True:

#!/bin/bash

B=" "

if [ -n $B ]; then
        echo "passed 1"
fi

if [ $B ]; then
        echo "passed 2"
fi


However it seems to me the variable expansion plays a role here, I'm not
sure if the variable expansion was supposed to differ between "$B" and
"-n $B" too, so perhaps it's a bash thing not a "test" thing?

Cheers,
Carlos



Reply via email to