-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_12_13_case_statement.sh
More file actions
74 lines (37 loc) · 1.25 KB
/
tutorial_12_13_case_statement.sh
File metadata and controls
74 lines (37 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /bin/bash
#basic syntax for case statement
# case expression in
# pattern1 )
# statements ;;
# pattern2 )
# statements ;;
# ...
# esac
vehicle=$1 #will take input from command line arguments
case $vehicle in
"car" )
echo "Rent of the $vehicle is 100 dollar" ;;
"van" )
echo "Rent of the $vehicle is 80 dollar" ;;
"bike" )
echo "Rent of the $vehicle is 50 dollar" ;;
"bicycle" )
echo "Rent of the $vehicle is 20 dollar" ;;
* ) # default case that means any wildcard string
echo "This vehical is unknown" ;;
esac
echo -e "Enter some character: \c"
read value
case $value in
[a-z] ) # it means it will check if given character is lowercase
echo "$value is lowercase" ;;
[A-Z] ) #will check if given character is uppercase
echo "$value is uppercase" ;;
[0-9] ) #will check if given character is digit
echo "$value is digit" ;;
? ) #will check if given character is special character or symbol (one)
echo "$value is special symbol" ;;
* ) # default case for more than one characters
echo "unknown input" ;;
esac
# To learn more about pattern matching read the wikipedia page for regular expressions