Welcome to %1$s. Please log in.

Login with username, password and session length
 
News: Keep The TechnoWorldInc.com Community Clean: Read Guidelines Here.
Techno World Inc - The Best Technical Encyclopedia Online! | Forum | THE TECHNO CLUB [ TECHNOWORLDINC.COM ] | Programming Zone | Shell Script | Bourne/bash shell scripts: if statement syntax

Mark David

Bourne/bash shell scripts: if statement syntax

Conditional expressions give programs life. The ability to branch makes shell scripts powerful. This recipe shows the basic if then else structure for sh, ksh, bash, zsh, etc.

if [ condition_A ]
then
   code to run if condition_A true
elif [ condition_B ]
then
   code to run if condition_A false and condition_B true
else
   code to run if both conditions false
fi


Multiple elif blocks can be strung together to make an elaborate set of conditional responses.

Recent Updates

[August 11, 2025, 08:33:44 AM]

[August 11, 2025, 08:33:44 AM]

[August 11, 2025, 08:33:44 AM]

[August 11, 2025, 08:33:44 AM]

[May 13, 2025, 08:34:25 AM]

[May 13, 2025, 08:34:25 AM]

[May 13, 2025, 08:34:25 AM]

[April 12, 2025, 08:24:20 AM]

[April 12, 2025, 08:24:20 AM]

[April 12, 2025, 08:24:20 AM]

[April 12, 2025, 08:24:20 AM]

[March 12, 2025, 09:35:30 AM]

[March 12, 2025, 09:35:30 AM]

Subscriptions

Get Latest Tech Updates For Free!

Resources

  

Bourne/bash shell scripts: if statement syntax

Started by Mark David, March 16, 2007, 08:03:58 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

  Print     Print       Print