测试布尔值和字符串



我想检查是否设置了两个选项之一:提供bintruestr

bin=false; str=; if $bin -o [ -n "$str" ]; then echo yes; fi

echo没有像它应该的那样做任何事情,但是:

bin=false; str='str'; if $bin -o [ -n "$str" ]; then echo yes; fi

也没有回音——而它应该。我做错了什么?

您的-o选项正在传递给false。您需要||:

bin=false; str=; if $bin || [ -n "$str" ]; then echo yes; fi
bin=false; str='str'; if $bin || [ -n "$str" ]; then echo yes; fi

最新更新