问题
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
andendif
must appear at the beginning of input lines; theif
must appear alone on its input line or after anelse
.)
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