#! /bin/bash
read str1
read str2
if [ -z "$str1" ]
#if [ -z $str1 ]
then
echo "$str1 is void"
echo "-z:void return value is 1" >>log.txt
else
echo "$str1 is not void"
echo "-z:not void return value is 0" >>log.txt
fi
if [ -n "$str1" ]
#if [ -n $str1 ]
then
echo "*** $str1 is not void"
echo "*** -n:not void return value is 1" >>log.txt
else
echo "$str1 is void"
echo "-n:void return value is 0" >>log.txt
fi
这段代码,在输入空字符时。判断语句中的双引号会有影响,从而导致第二个老是判断出错。有空搞明白。