ksh:a string can be empty and not empty at the same time ?!?

Hi,

Do you have the same result?

#string=$(ls /tmp/what_you_want)
ls: No such file or directory (/tmp/what_you_want)
#if test -n $string; then echo not empty; fi
not empty
#if test -z $string; then echo empty; fi
empty


Is it normal ?

Thanks
Alain.

Alain Bonnefoy a écrit :

Hi,

Do you have the same result?

#string=$(ls /tmp/what_you_want)
ls: No such file or directory (/tmp/what_you_want)
#if test -n $string; then echo not empty; fi
not empty
#if test -z $string; then echo empty; fi
empty

Is it normal ?

Thanks
Alain.

same in bash :astonished:(

Alain Bonnefoy wrote:

Alain Bonnefoy a écrit :

Hi,

Do you have the same result?

#string=$(ls /tmp/what_you_want)
ls: No such file or directory (/tmp/what_you_want)
#if test -n $string; then echo not empty; fi
not empty
#if test -z $string; then echo empty; fi
empty

Is it normal ?

Thanks
Alain.

same in bash > :astonished:> (

FYI, seems to work both in Solaris 7 and QNX 4.25,
if I add some double quotes in the test:

string=$(ls /tmp/what_you_want)

/tmp/what_you_want: No such file or directory

if test -n “$string”; then echo not empty; fi

if test -z “$string”; then echo empty; fi

empty

brgds


Per Åkesson
Carmenta AB
SWEDEN

Per Akesson a écrit :

Alain Bonnefoy wrote:

Alain Bonnefoy a écrit :

Hi,

Do you have the same result?

#string=$(ls /tmp/what_you_want)
ls: No such file or directory (/tmp/what_you_want)
#if test -n $string; then echo not empty; fi
not empty
#if test -z $string; then echo empty; fi
empty

Is it normal ?

Thanks
Alain.

same in bash > :astonished:> (

FYI, seems to work both in Solaris 7 and QNX 4.25,
if I add some double quotes in the test:

string=$(ls /tmp/what_you_want)

/tmp/what_you_want: No such file or directory

if test -n “$string”; then echo not empty; fi

if test -z “$string”; then echo empty; fi

empty

brgds


Per Åkesson
Carmenta AB
SWEDEN

You are right, I found the tips in an example but I complain that it’s
not clearly explained in none of the different docs I found about shell
script.

Thanks,
Alain.