The Wayback Machine - https://web.archive.org/web/20230512155752/https://www.geeksforgeeks.org/if-command-in-linux-with-examples/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

if command in linux with examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

if is a command in Linux which is used to execute commands based on conditions. The ‘if COMMANDS‘ list is executed. If its status is zero, then the ‘then COMMANDS‘ list is executed. Otherwise, each ‘elif COMMANDS‘ list is executed in turn, and if its exit status is zero, the corresponding ‘then COMMANDS‘ list is executed and the if command completes. Otherwise, the ‘else COMMANDS‘ list is executed, if present. The exit status of the entire construct is the exit status of the last command executed, or zero if no condition tested true.

Syntax:

if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi

Example:

Options:

  • help if : It displays help information.

My Personal Notes arrow_drop_up
Last Updated : 22 May, 2019
Like Article
Save Article
Similar Reads