Thursday, May 19, 2022

Bash Scripting 6

 Conditional Statement in Bash




Conditional statement :
  • Conditional statement plays a vital role in programming.
  • Every decision making part can be done with conditional statement.
  • Conditional statement in bash is similar to python .But the coding style differ.
  • Common conditional Statements are:
    • if statement
    • if-else statement
    • if-elif-else statement
    • switch cases
  • These are the common conditional statement.
  • Most of the popular programming language use these in the same format with slight modifications.

If else statement:
  • Syntax:

  • The if condition should be terminated with "fi" which is nothing but the reverse of "if".
  • Lets see a example,


If-elif-else statement:
  • Syntax:
  • Example : find the largest of three number:


Case statement similar to switch statements:
  • Syntax:

  • Printing the numbers in letter format:




  • In python we use break after each condition similarly here we use ";;"
  • The case condition statement should end with "esac" which is the reverse of case.


No comments:

Post a Comment

Google Cybersecurity Professional Certificate

    Google Cybersecurity Professional Certification 🔒 Google Cybersecurity Professional Certification: A Journey Unveiled! 🔒 Hey Folks! 🌟...