

# Delete all the lines matches with the pattern p) echo "Lines matches with the pattern $2 :" c) echo "Number of words matches with the pattern $2 :" i) echo "Number of lines matches with the pattern $2 :" $ cat fileop.shĮcho "Usage : $0 option pattern filename"Įcho "Filename given \"$3\" doesn't exist" This example prints the number of lines,number of words and delete the lines that matches the given pattern. $ sleep 1000Īlso, refer to our earlier kill article – 4 methods to kill a process. Usage of the above shell script: Find out the process id of the sleep command and send kill signal to that process id to kill the process.

If there is no match, exit status of case is zero.īash Case Example 1.After the first match, case terminates with the exit status of the last command that was executed.When a match is found all of the associated statements until the double semicolon ( ) are executed.

Case statement first expands the expression and tries to match it against each pattern.case expression inįollowing are the key points of bash case statements: Bash case statement is the simplest form of the bash if-then-else statement. The case construct in bash shell allows us to test strings against patterns that can contain wild card characters. In this article let us review the bash case command with 5 practical examples. Instead, bash shell checks the condition, and controls the flow of the program. It can be used to test simple values like integers and characters.Ĭase statement is not a loop, it doesn’t execute a block of code for n number of times.

Bash shell case statement is similar to switch statement in C.
