Skip to main content

Command Palette

Search for a command to run...

Bash Scripting – Case Statement

Published
β€’1 min readβ€’View as Markdown
Bash Scripting – Case Statement

#90 Days DevOps Challenge#Zero To Hero#Day11 πŸ’» Challenge Accepted with #tws by Shubham Londhe πŸ‘¨β€πŸ«

90 Days DevOps Challange@ Zero To Hero Journey # Day 1

Case statement in bash scripts is used when a decision has to be made against multiple choices. In other words, it is useful when an expression has the possibility to have multiple values.

Syntax:

case EXPRESSION in
  Pattern_Case_1)
   STATEMENTS
   ;;
 Pattern_Case_1)
   STATEMENTS
   ;;
 Pattern_Case_N)
   STATEMENTS
   ;;
 *)
   STATEMENTS
   ;;
esac

Output a Description for Each Option

  • The first line in the script starts with the shebang (#!).

  • It instructs the operating system to use a particular interpreter to parse the script.

  • We have initialized a PROFILE variable as β€œDevOps”.

  • Now, we are using a case statement.

  • Each expression has been handled through the case statement.

  • The last line, esac, has been used to terminate the case statement.

More from this blog

Akash Raj

16 posts