Linux Bash If-Else Conditionals

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-bash-else-conditionals/
PINTEREST
PINTEREST
INSTAGRAM
  1. Introduction To Linux Bash Programming
  2. Linux Bash Directories and Files
  3. Linux Bash Environment Variables
  4. Linux Bash Variables
  5. Linux Bash Functions
  6. Linux Bash If Else Conditionals
  7. Linux Bash Create and Run Script Files
  8. Linux Bash Operators
  9. Linux Bash Arrays
  10. Linux Bash Input, Output and Redirection
  11. Linux Bash History
  12. Linux Bash Alias
  13. Linux Bash .bashrc File
  14. Linux Bash Debugging

If-Elif operators are used to design flow of the bash script. We can change the flow according to given conditions with If-Elif .

If

When writing scripts we have a lot of situation to make decision. We solve the questions marks of the scripts with conditionals. For example the simplest one is we want to run script if a directory or file exist.

If  Clean.sh exists then echo

The most used and simple conditional is if/then/else statement. Statement starts with if and lists conditions and closed with fi. Here [ … ] brackets look for file and provide logic for if. Do not be afraid there is a lot of functions to test a lot of thing. We will touch some of them.

Multiple Conditions with If – Elif

Here we have to focus of elif statement which adds new condition to the if statement. If the count is 12 do this else if count is 11 do this. Simple isn’t it?

LEARN MORE  How To Check Whether A File Exists Using Python?

File Test Operators

While scripting there will be a lot of file interactions. Bash provides a lot of options for file testing. For example to check if a file exist use the following statement

Comparison Operators

In order to compare two or more variables or values comparison operators are used. In this example is the count is greater than 5 below example is used. The greater than operator is -gt .

  1. Introduction To Linux Bash Programming
  2. Linux Bash Directories and Files
  3. Linux Bash Environment Variables
  4. Linux Bash Variables
  5. Linux Bash Functions
  6. Linux Bash If Else Conditionals
  7. Linux Bash Create and Run Script Files
  8. Linux Bash Operators
  9. Linux Bash Arrays
  10. Linux Bash Input, Output and Redirection
  11. Linux Bash History
  12. Linux Bash Alias
  13. Linux Bash .bashrc File
  14. Linux Bash Debugging
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-bash-else-conditionals/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)