如何在鱼中的连接条件
我正在尝试使用两个条件在鱼中使用IF块。这个想法很简单: 我想检查图像文件是否太宽,太高或两者兼而有之。 所以我写了以下脚本。
#!/bin/fish
set bla (identify $argv[1])
set blabla (string split ' ' $bla)
set siiz (string split x $blabla[3])
set xsiz $siiz[1]
set ysiz $siiz[2]
if test (test $xsiz -gt 1600) -a (test $ysiz -gt 900)
echo "both $xsiz $ysiz"
else if test $ysiz -gt 900
echo "tall"
else if test $xsiz -gt 1600
echo "wide"
end
我已经进行了检查,以查看变量XSIZ和YSIZ具有正确的 值。 但是,无论我将脚本传递给脚本,它总是返回“两个”(甚至使用20 x 20像素的图像)´ 如果我尝试在没有括号或内部test
命令的情况下传递test
命令,Fish将抱怨未识别的命令。 这些文档没有关于这样的组成条件的例子。
I am trying to use a if block in fish using two conditions. The idea is simple:
I want to check if an image file is too wide, too tall, or both.
So I wrote the following script.
#!/bin/fish
set bla (identify $argv[1])
set blabla (string split ' ' $bla)
set siiz (string split x $blabla[3])
set xsiz $siiz[1]
set ysiz $siiz[2]
if test (test $xsiz -gt 1600) -a (test $ysiz -gt 900)
echo "both $xsiz $ysiz"
else if test $ysiz -gt 900
echo "tall"
else if test $xsiz -gt 1600
echo "wide"
end
And I already performed check to see that the variables xsiz and ysiz have the right
values.
But no matter what I pass to the script, it always returns "both" (even using images of 20 by 20 pixels)´
If I try to pass the test
command without the parenthesis or the inner test
commands, fish will complain about not recognized commands.
The docs have none examples about a composed condition like this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使它比需要的要复杂。请注意,命令替代命令除
set
命令的特殊情况外。您的版本等同于此:总是回荡“是”(为什么
false
不会导致测试评估为false是应该修复的语言的怪癖,恕我直言)。只需进行一次测试:
You're making it more complicated than it needs to be. Note that command substitution doesn't capture the exit status of the command except for the special case of the
set
command. Your version is equivalent to this:That always echoes "yes" (why the
false
doesn't cause the test to evaluate to false is a quirk of the language that should be fixed, IMHO).Just do a single test: