53
Bash Script

Bash script final

Embed Size (px)

Citation preview

Page 1: Bash script final

Bash Script

Page 2: Bash script final
Page 3: Bash script final

• 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

Let’s explore Bash Script…

Page 5: Bash script final

1.Variables

Page 6: Bash script final
Page 7: Bash script final

Global vs. Local variables

Page 8: Bash script final

2.Conditional statements and loops

Page 9: Bash script final

A.Conditional statements

Page 10: Bash script final

If/else

Page 11: Bash script final

Elif

Page 12: Bash script final

Arithmetic Comparisons

Page 13: Bash script final

Case

Page 14: Bash script final

b.Loops

Page 15: Bash script final

While

Page 16: Bash script final

For(with numbers)

Page 17: Bash script final

For(with directories)

Page 18: Bash script final

For(with arrays)

Page 19: Bash script final

Until

Page 20: Bash script final

3.Bash functions

Page 21: Bash script final

Syntax to create a bash function:

Page 22: Bash script final

Function with arguments

Page 23: Bash script final

Functions with returned values

Page 24: Bash script final

4.String manipulations

Page 25: Bash script final

a.String length

Page 26: Bash script final

b.Substring extraction

Page 27: Bash script final

c.Shortest Substring Match

Page 28: Bash script final

d.Find and Replace String Values

Page 29: Bash script final

e.Replace all the matches

Page 30: Bash script final

f.Replace beginning and end

Page 31: Bash script final

f.Replace beginning and end

Page 32: Bash script final

5.I/O Redirection

Page 33: Bash script final

a.Standard Output “>”

Page 34: Bash script final

a.Standard Output “>”

Page 35: Bash script final

b.Standard Input “<“

Page 36: Bash script final

b.Standard Input “<“

Page 37: Bash script final

c.Pipes “|”

Page 38: Bash script final
Page 39: Bash script final

6.Special commands

Page 40: Bash script final

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
Page 42: Bash script final

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
Page 44: Bash script final
Page 45: Bash script final
Page 46: Bash script final

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
Page 48: Bash script final
Page 49: Bash script final

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
Page 51: Bash script final
Page 52: Bash script final

e.Alias

• Is used to enable a replacement of a command by another string

• Syntax : alias myalias=“command_name”

Page 53: Bash script final

Thank you for your attention