07 String - kumar159man/MyShellLearning GitHub Wiki
Use # to get variable name
myubuntu@myubuntu-VirtualBox:~$ c="CHELSEA" myubuntu@myubuntu-VirtualBox:~$ echo "Length of the string is ${#c}" Length of the string is 7
myubuntu@myubuntu-VirtualBox:~$ c="Chelsea" myubuntu@myubuntu-VirtualBox:~$ d=" is a dog" myubuntu@myubuntu-VirtualBox:~$ echo "$c$d" Chelsea is a dog myubuntu@myubuntu-VirtualBox:~$ e=$c$d myubuntu@myubuntu-VirtualBox:~$ echo "$e" Chelsea is a dog
myubuntu@myubuntu-VirtualBox:~$ c="chelsea" myubuntu@myubuntu-VirtualBox:~$ echo "${c^^}" CHELSEA
myubuntu@myubuntu-VirtualBox:~$ echo "${c,,}" chelsea
dirname and basename commands are very important while working with paths
- dirname-> removes file name from directoy
- basename-> gives only file name
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ dirname /home/myubuntu/Desktop/shellScripts/cut.txt /home/myubuntu/Desktop/shellScripts myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ basename /home/myubuntu/Desktop/shellScripts/cut.txt cut.txt
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ d=$(dirname /home/myubuntu/Desktop/shellScripts/cut.txt) myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ e=$(basename /home/myubuntu/Desktop/shellScripts/cut.txt) myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ echo "$d" /home/myubuntu/Desktop/shellScripts myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ echo "$e" cut.txt
slicing can be done through cut command
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ d="Chelsea" myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ echo $d | cut -c 1,3 Ce
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ c="Chelsea" myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ echo "${c:0}" Chelsea
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ echo "${c:1}" helsea
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ echo "${c:2:1}" e
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ echo "${c:2:3}" els
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ cat third.sh #!/usr/bin/bash source ./variables.txt . ./first.sh echo "Value of x is $x" echo "Value of y is $y" echo "Value of dog is $dog" <<mycomment1 echo "Comment line1" echo "Comment line2" echo "Comment line3" mycomment1 myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ ./third.sh Hello this is my first shell script Value of x is 18 Value of y is 20 Value of dog is Chelsea myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$
Applying these concepts and creating script for installing tomcat tomcat installation script