$test -n && echo true || echo false-> true
而
$test -n "" && echo true || echo false-> false
这意味着当它根本没有收到任何参数时,它假定为非零.
案例-z正常工作:
$test -z && echo true || echo false-> true$test -z "" && echo true || echo false-> true
这是预期的行为吗?
解决方法 基本上,您要测试字符串“-z”是否为非空.它是,所以它告诉你真实.实际算法测试使用的是:0 arguments:
Exit false (1).
1 argument:
Exit true (0) if $1 is not null; otherwise,exit false.
2 arguments:
If $1 is ‘!’,exit true if $2 is null,false if $2 is not null.
If $1 is a unary primary,exit true if the unary test is true,false
if the unary test is false.Otherwise,produce unspecifIEd results.
…
引自the POSIX test command specification.
总结以上是内存溢出为你收集整理的linux – BASH:[](测试)表现不一致全部内容,希望文章能够帮你解决linux – BASH:[](测试)表现不一致所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)