0% found this document useful (0 votes)
6 views

Lecture On Bash Shell Script

The document discusses various uses of shell scripts including executing commands, running multiple commands together, customizing administrative tasks, and performing task automation. It covers basic script elements like variables, conditional statements, loops, functions, input/output redirection and parsing dates. Key points include using shell commands like echo, read, if/then, case, for/while loops, and checking file permissions and existence.

Uploaded by

kounglay mmt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lecture On Bash Shell Script

The document discusses various uses of shell scripts including executing commands, running multiple commands together, customizing administrative tasks, and performing task automation. It covers basic script elements like variables, conditional statements, loops, functions, input/output redirection and parsing dates. Key points include using shell commands like echo, read, if/then, case, for/while loops, and checking file permissions and existence.

Uploaded by

kounglay mmt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

2

▪ various purposes

➢ Executing a shell command

➢ Running multiple commands together

➢ Customizing administrative tasks

➢ Performing task automation etc.


3

Use of terminal or editor


$ bash filename

▪ Cat>filename Or

▪ “vi” editor or “nano” editor $ chmod a+x filename

▪ Use of file extension ➔ “ .sh “ $ ./filename


4
5
6

▪ ‘echo’ command without any option then a newline is added by default

▪ ‘-n’ option is used to print any text without new line

▪ ‘-e’ option is used to remove backslash characters from the output


7
‘#’ symbol is used to add single line comment
8
▪ ‘:’ and “ ’ ” symbols are used to add multiline comment
9

while [ condition ]

do

statement

done
10

for (( operation; condition; operation ))

do

statement

done
11
‘read’ command is used to take input from user
12

if [ condition ];

then

statement

fi
13
14
15
16

case expression in

pattern1)

statement ;;

pattern2)

statement ;;

esac
17
18
19
20
▪ combine string variables in bash by placing variables together or using ‘+’ operator
21

Need to assign start &


end value
22
▪ Use of double brackets
23
24
25
▪ Bash function can pass both numeric and string values
26
27
▪ ‘-d’ option is used to test a particular directory is exist or not
28
▪ Read any file line by line in bash by using loop
29
▪ ‘-i’ option is used to get permission from the user before removing the file
30
▪ ‘>>’ option is used to append text into a file
31
▪ ‘-f’ option is used in the following script to test the file existence
32
▪ Every part of date and time value can be parsed using ‘Y’, ‘m’, ‘d’, ‘H’, ‘M’ and ‘S’

You might also like