1
我想做如何.csh脚本
a = $b == howru ? good : not_good;
在C shell脚本
我尝试使用&&
和||
运营商做一个三元操作,但好像我做了一些错误,因为我习惯于在Bash上工作。
我想做如何.csh脚本
a = $b == howru ? good : not_good;
在C shell脚本
我尝试使用&&
和||
运营商做一个三元操作,但好像我做了一些错误,因为我习惯于在Bash上工作。
首先,你的语法是错误的:
set
?
分配变量.. :
不是在csh操作。“正常” csh
if
语句如下:
if (cond) then
foo
else
bar
endif
实际上,你可以缩短if
到
if (cond) foo
但你不能在这里添加else
,就我知道。
“短”语法的作品完全一样的Bourne shell,除非你需要使用set
关键字:
% [ "howru" = 'howru' ] && set a = good || set a = not_good
% echo $a
good
% [ "XXhowru" = 'howru' ] && set a = good || set a = not_good
% echo $a
not_good
非常感谢..它的工作 – 2015-03-03 07:01:49
TusharGarg请接受来自@Carpetsmoker的答案如果你觉得这是正确的,请纠正,不要只写评论。 – fork2execve 2015-03-16 20:08:22