The truth about -z and -n
if [ -z $null ]
then
echo '$null is null'
else
echo '$null file is not null.'
fi
if [ -n $null ]
then
echo '$null file is not null.'
else
echo '$null is null'
fi
The output is
$$null is null
$$null file is not null.
Not quite as we expected,So we learn that we should always quote the tested string and -n needs it.
if [ -z $null ]
then
echo '$null is null'
else
echo '$null file is not null.'
fi
if [ -n "$null" ]
then
echo '$null file is not null.'
else
echo '$null is null'
fi
then
echo '$null is null'
else
echo '$null file is not null.'
fi
if [ -n $null ]
then
echo '$null file is not null.'
else
echo '$null is null'
fi
The output is
$$null is null
$$null file is not null.
Not quite as we expected,So we learn that we should always quote the tested string and -n needs it.
if [ -z $null ]
then
echo '$null is null'
else
echo '$null file is not null.'
fi
if [ -n "$null" ]
then
echo '$null file is not null.'
else
echo '$null is null'
fi
0 Comments:
Post a Comment
<< Home