-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertCase.sh
executable file
·48 lines (36 loc) · 1.04 KB
/
convertCase.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
46
47
48
#!/usr/bin/env bash
echo -e "Choose an option\n1. String conversion\n2. File Conversion"
read choice
case $choice in
1 ) read -p "Enter the string : " string
echo -e "***Choose one of the option***\n1. UpperCase\n2. LowerCase\n"
read strCaseType
case $strCaseType in
1 ) echo $string | tr "[[:lower:]]" "[[:upper:]]"
;;
2 ) echo $string | tr "[[:upper:]]" "[[:lower:]]"
;;
* ) echo "Invalid option!"; exit 1
;;
esac
;;
2 ) read -p "Enter the file name : " filename
if [[ ! -f "$filename" ]]; then
echo "File doesn't exists."
exit 1
fi
result=$(cat $filename)
read -p "Enter the output file name : " outFile
echo -e "***Choose one of the option***\n1. UpperCase\n2. LowerCase\n"
read caseType
case $caseType in
1 ) echo $result | tr "[[:lower:]]" "[[:upper:]]" >> $outFile
;;
2 ) echo $result | tr "[[:upper:]]" "[[:lower:]]" >> $outFile
;;
* ) echo "Invalid option!"; exit 1
;;
esac
echo "Done ."
;;
esac