-
Notifications
You must be signed in to change notification settings - Fork 0
/
22_upper_lower.sh
47 lines (40 loc) · 1007 Bytes
/
22_upper_lower.sh
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
<<Documentation
NAME : V.Karthikeyan
DATE : 17.05.2021
DESCRIPTION : Shell script to convert string lower to upper and upper to lower
INPUT : ./22_upper_lower.sh file.txt
OUTPUT :
1-Lower to upper
2-Upper to Lower
Please select option: 1
LINE NUMBER 1
LINE NUMBER 2
LINE NUMBER 3
LINE NUMBER 4
Documentation
if [ $# -eq 0 ] #check if argument is passed through command line, else exit
then
echo "Please pass the file name through command line"
exit
elif ! [ -e $1 ] #if file not exist, print error msg and exit
then
echo "File is not exist"
exit
elif ! [ -s $1 ] #if file has no contents, print error msg and exit
then
echo "No contents inside the file"
exit
fi
echo -e "1-Lower to upper \n2-Upper to Lower"
read -p "Please select option: " n #read option from user
case $n in
1)
cat $1 | tr a-z A-Z #lower case to upper case
;;
2)
cat $1 | tr A-Z a-z #upper case to lower case
;;
*)
echo "Invalid choice"
exit
esac