我想要做
a = $b == howru ? good : not_good;
Run Code Online (Sandbox Code Playgroud)
在c shell脚本中
我尝试使用&&and||运算符,但似乎我犯了一些错误,因为我习惯在 Bash 上工作。
首先,你的语法是错误的:
set?..:不是 csh 中的运算符。“正常”的csh if声明如下:
if ( cond ) then
foo
else
bar
endif
Run Code Online (Sandbox Code Playgroud)
你实际上可以缩短if到
if ( cond ) foo
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)