我想检查是否设置了两个选项之一:提供bin
到true
或str
:
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