Javatpoint Logo

91-9990449935

 0120-4256464

Javatpoint Logo

Shell Scripting case

A case construct helps us to simplify nested if statement. You can match several variables against one variable. Each case is an expression matching a certain pattern.

Syntax:

Linux Shell Scripting Case 1

Look at the above snapshot, you can write one pattern or more than one pattern together according to the situation. Let's see an example to understand it more clearly.

Example:

Linux Shell Scripting Case 2

Look at the above snapshot, we have shown a script to show the capital of different states. States Punjab and Haryana are written together as they share same capital.

Output:

Linux Shell Scripting Case 3

Look at the above snapshot, user can enter a state name and script will display its capital respectively.

Next TopicScripting eval




Share this page

facebook twitter google plus pinterest tumbler

Latest 4 Tutorials