bash script

53
Bash Script

Upload: okba-mahdjoub

Post on 27-Jun-2015

222 views

Category:

Documents


7 download

DESCRIPTION

introduction to bash script

TRANSCRIPT

Page 1: Bash script

Bash Script

Page 2: Bash script
Page 3: Bash script

• 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

Let’s explore Bash Script…

Page 5: Bash script

1.Variables

Page 6: Bash script
Page 7: Bash script

Global vs. Local variables

Page 8: Bash script

2.Conditional statements and loops

Page 9: Bash script

A.Conditional statements

Page 10: Bash script

If/else

Page 11: Bash script

Elif

Page 12: Bash script

Arithmetic Comparisons

Page 13: Bash script

Case

Page 14: Bash script

b.Loops

Page 15: Bash script

While

Page 16: Bash script

For(with numbers)

Page 17: Bash script

For(with directories)

Page 18: Bash script

For(with arrays)

Page 19: Bash script

Until

Page 20: Bash script

3.Bash functions

Page 21: Bash script

Syntax to create a bash function:

Page 22: Bash script

Function with arguments

Page 23: Bash script

Functions with returned values

Page 24: Bash script

4.String manipulations

Page 25: Bash script

a.String length

Page 26: Bash script

b.Substring extraction

Page 27: Bash script

c.Shortest Substring Match

Page 28: Bash script

d.Find and Replace String Values

Page 29: Bash script

e.Replace all the matches

Page 30: Bash script

f.Replace beginning and end

Page 31: Bash script

f.Replace beginning and end

Page 32: Bash script

5.I/O Redirection

Page 33: Bash script

a.Standard Output “>”

Page 34: Bash script

a.Standard Output “>”

Page 35: Bash script

b.Standard Input “<“

Page 36: Bash script

b.Standard Input “<“

Page 37: Bash script

c.Pipes “|”

Page 38: Bash script
Page 39: Bash script

6.Special commands

Page 40: Bash script

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

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

c.Awk

• Is used to print specific lines and columns from a file, with conditions.• Syntax : awk '{print $NF}' file

Page 47: Bash script
Page 48: Bash script
Page 49: Bash script

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

e.Alias

• Is used to enable a replacement of a command by another string• Syntax : alias myalias=“command_name”

Page 53: Bash script

Thank you for your attention