How to write If-else statement in one line in csh?

强颜欢笑 提交于 2019-12-10 23:57:41

问题


I use Cshell and i'm writing an if else statement in oneLine.

If statement executed successfully and else block is going for infinite loop and cannot exit back to promt.

Any suggestion how it can be solved?

/home/sun_cdmasee>if ( 25 == 25 )  then ; echo "yes" ; else  echo "no" ; endif

yes

else?

else?

else?


回答1:


The man page says it's not possible:

(The words else and endif must appear at the beginning of input lines; the if must appear alone on its input line or after an else.)

Don't try to program in csh. Don't even use it as your interactive shell.

Incidentally, you can exit back to your normal csh prompt by typing endif at the else? prompt.




回答2:


Yes, you can!
in tcsh (which is invariably available on recent Linux distributions, even MacOS)

if ( $?debug_log ) echo "verbose output for debugging purposes ${shell_variable}"


来源:https://stackoverflow.com/questions/33729915/how-to-write-if-else-statement-in-one-line-in-csh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!