2015-03-02 79 views
1

我想做如何.csh脚本

a = $b == howru ? good : not_good; 

在C shell脚本

我尝试使用&&||运营商做一个三元操作,但好像我做了一些错误,因为我习惯于在Bash上工作。

回答

2

首先,你的语法是错误的:

  1. 您需要与set
  2. ?分配变量.. :不是在csh操作。

“正常” cshif语句如下:

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 
+0

非常感谢..它的工作 – 2015-03-03 07:01:49

+0

TusharGarg请接受来自@Carpetsmoker的答案如果你觉得这是正确的,请纠正,不要只写评论。 – fork2execve 2015-03-16 20:08:22