bash script final
TRANSCRIPT
![Page 1: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/1.jpg)
Bash Script
![Page 2: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/2.jpg)
![Page 3: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/3.jpg)
• Bash is a Unix shell written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell .
• Released in 1989,it has been distributed widely as the shell for the GNU operating system and as a default shell on Linux and Mac OS X.
![Page 4: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/4.jpg)
Let’s explore Bash Script…
![Page 5: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/5.jpg)
1.Variables
![Page 6: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/6.jpg)
![Page 7: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/7.jpg)
Global vs. Local variables
![Page 8: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/8.jpg)
2.Conditional statements and loops
![Page 9: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/9.jpg)
A.Conditional statements
![Page 10: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/10.jpg)
If/else
![Page 11: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/11.jpg)
Elif
![Page 12: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/12.jpg)
Arithmetic Comparisons
![Page 13: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/13.jpg)
Case
![Page 14: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/14.jpg)
b.Loops
![Page 15: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/15.jpg)
While
![Page 16: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/16.jpg)
For(with numbers)
![Page 17: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/17.jpg)
For(with directories)
![Page 18: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/18.jpg)
For(with arrays)
![Page 19: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/19.jpg)
Until
![Page 20: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/20.jpg)
3.Bash functions
![Page 21: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/21.jpg)
Syntax to create a bash function:
![Page 22: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/22.jpg)
Function with arguments
![Page 23: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/23.jpg)
Functions with returned values
![Page 24: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/24.jpg)
4.String manipulations
![Page 25: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/25.jpg)
a.String length
![Page 26: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/26.jpg)
b.Substring extraction
![Page 27: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/27.jpg)
c.Shortest Substring Match
![Page 28: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/28.jpg)
d.Find and Replace String Values
![Page 29: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/29.jpg)
e.Replace all the matches
![Page 30: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/30.jpg)
f.Replace beginning and end
![Page 31: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/31.jpg)
f.Replace beginning and end
![Page 32: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/32.jpg)
5.I/O Redirection
![Page 33: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/33.jpg)
a.Standard Output “>”
![Page 34: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/34.jpg)
a.Standard Output “>”
![Page 35: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/35.jpg)
b.Standard Input “<“
![Page 36: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/36.jpg)
b.Standard Input “<“
![Page 37: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/37.jpg)
c.Pipes “|”
![Page 38: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/38.jpg)
![Page 39: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/39.jpg)
6.Special commands
![Page 40: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/40.jpg)
a.Grep
• Is used to search a characters chain within a file• -v displays the lines that do not contain the string
• -c count the number of lines containing the string
• -n each line containing the string is numbered
• -x the line that exactly matches the string
• -l displays the names of files that contain the string
![Page 41: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/41.jpg)
![Page 42: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/42.jpg)
b.Find
• Is used to fined files based on specific criteria.
• Syntax: find <folder> <search criteria>
• -name search by name
• -perm search by access rihghts on file,
• -user search by file’s owner,
• -group search by file’s group,
![Page 43: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/43.jpg)
![Page 44: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/44.jpg)
![Page 45: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/45.jpg)
![Page 46: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/46.jpg)
c.Awk
• Is used to print specific lines and columns from a file, with conditions.
• Syntax : awk '{print $NF}' file
![Page 47: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/47.jpg)
![Page 48: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/48.jpg)
![Page 49: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/49.jpg)
d.Sed
• The SED UNIX Command in Linux enables you to work with the text inside your files and can be used to perform different functions to it.
• Syntax :
![Page 50: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/50.jpg)
![Page 51: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/51.jpg)
![Page 52: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/52.jpg)
e.Alias
• Is used to enable a replacement of a command by another string
• Syntax : alias myalias=“command_name”
![Page 53: Bash script final](https://reader031.vdocument.in/reader031/viewer/2022020101/55a1689d1a28ab6b258b4708/html5/thumbnails/53.jpg)
Thank you for your attention