bash的条件语句:如何"和"前pressions? (如果[-z $ VAR和放大器;!&安培; -e $ VAR]) [英] bash conditionals: how to "and" expressions? (if [ ! -z $VAR && -e $VAR ])
本文介绍了bash的条件语句:如何"和"前pressions? (如果[-z $ VAR和放大器;!&安培; -e $ VAR])的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我不是如何做和试验清楚。我想,以确保存在的参数,它与运行良好[-e $ VAR]
,但事实证明,也被评估对空字符串为真;我不想要的。
我如何'和'在一起?还是有另一种一元的测试完成我想要什么?
解决方案
如果[! -z$ VAR]放;&安培; [-e$ VAR];然后
#东西...
科幻
I guess I'm not clear on how to do "and" tests. I wanted to make sure an argument existed which was working well with [ -e $VAR ]
but turns out that was also evaluating as true on empty string; which I do not want.
How do I 'and' them together? Or is there another unary test that accomplishes what I want?
解决方案
if [ ! -z "$var" ] && [ -e "$var" ]; then
# something ...
fi
这篇关于bash的条件语句:如何"和"前pressions? (如果[-z $ VAR和放大器;!&安培; -e $ VAR])的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文