csh/C shell scripts: if statement syntax

Posted January 9, 2004 by Rex in csh shell scripting

Conditional expressions give programs life. The ability to branch makes shell scripts powerful. This recipe shows the basic if then else structure for csh, the C shell.


Basic if statement syntax:

if (condition) then
commands
endif

The addition of one or more else keywords offers additional flexibility:

if (condition) then
commands
else if (other condition) then
commands
else
commands
endif

The Conversation

Follow the reactions below and share your own thoughts.