SlideShare a Scribd company logo
Lab 7 – Bash Script CIE 302 - Operating
systems
What is bash scripting?
Bash script: a plain text that contains a series of commands, which
can be used to write Linux commands in the terminal.
Anything you can run normally on the command line can be put into
a script and it will do exactly the same thing.
Bash scripts an extension of .sh (myscript.sh). However, Linux is an
extensionless system so a script doesn't necessarily have to have this
characteristic in order to work.
How to execute a bash script?
 ./script → it will execute the script file, as
a new child process within the
bash/terminal.
 to grant permissions, to execute file:
chmod 755 script1 ⇔
(rwxr-xr-x) The file's owner may read, write, and execute the file. All
others may read and execute the file.
Script format
#!/bin/bash ⇔ The first line in code, must start with “#!”.
# A sample Bash script ⇔ comment line, not executed.
echo Hello World! ⇔ actual command that could be directly written in the terminal.
Variables
To declare a variable:
$a, $A, $a1A.
To initialize a variable
 a=4
To display the variable and its value
 echo $a
Variable substitution
var='Hello Student'
text=" $var Ahmed"
echo $text
If statements
If statements
For loop
While loop
Functions
To declare a variable:
$a, $A, $a1A.
To initialize a variable
 a=4
To display the variable and its value
 echo $a
Variable substitution
var='Hello Student'
text=" $var Ahmed"
echo $text

More Related Content

Similar to Lab 7 - Bash Script.pptx

Operating System Practice : Meeting 7- working with bash shell-a-slide
Operating System Practice : Meeting 7- working with bash shell-a-slideOperating System Practice : Meeting 7- working with bash shell-a-slide
Operating System Practice : Meeting 7- working with bash shell-a-slide
Syaiful Ahdan
 
Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linuxNorberto Angulo
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
Anu Chaudhry
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Scriptstudent
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scripting
Akshay Siwal
 
basic shell scripting syntex
basic shell scripting syntexbasic shell scripting syntex
basic shell scripting syntexKsd Che
 
Shellscripting
ShellscriptingShellscripting
Shellscripting
Narendra Sisodiya
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
VIKAS TIWARI
 
Using Unix
Using UnixUsing Unix
Using UnixDr.Ravi
 
UnixShells.ppt
UnixShells.pptUnixShells.ppt
UnixShells.ppt
EduardoGutierrez111076
 
bash
bashbash
BACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docxBACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docx
wilcockiris
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
Amit Ghosh
 
Shell & Shell Script
Shell & Shell ScriptShell & Shell Script
Shell & Shell Script
Amit Ghosh
 
Raspberry pi Part 4
Raspberry pi Part 4Raspberry pi Part 4
Raspberry pi Part 4
Techvilla
 
Bash vs. vista_power_shell
Bash vs. vista_power_shellBash vs. vista_power_shell
Bash vs. vista_power_shell
Thomas Lee
 
OverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxOverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docx
alfred4lewis58146
 

Similar to Lab 7 - Bash Script.pptx (20)

Operating System Practice : Meeting 7- working with bash shell-a-slide
Operating System Practice : Meeting 7- working with bash shell-a-slideOperating System Practice : Meeting 7- working with bash shell-a-slide
Operating System Practice : Meeting 7- working with bash shell-a-slide
 
Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linux
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
Bash shell
Bash shellBash shell
Bash shell
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Script
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scripting
 
basic shell scripting syntex
basic shell scripting syntexbasic shell scripting syntex
basic shell scripting syntex
 
Shellscripting
ShellscriptingShellscripting
Shellscripting
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Using Unix
Using UnixUsing Unix
Using Unix
 
UnixShells.ppt
UnixShells.pptUnixShells.ppt
UnixShells.ppt
 
bash
bashbash
bash
 
Unixscripting
UnixscriptingUnixscripting
Unixscripting
 
BACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docxBACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docx
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
 
Shell & Shell Script
Shell & Shell ScriptShell & Shell Script
Shell & Shell Script
 
Raspberry pi Part 4
Raspberry pi Part 4Raspberry pi Part 4
Raspberry pi Part 4
 
Bash vs. vista_power_shell
Bash vs. vista_power_shellBash vs. vista_power_shell
Bash vs. vista_power_shell
 
Shell Basics
Shell BasicsShell Basics
Shell Basics
 
OverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxOverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docx
 

More from NourhanTarek23

CSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdfCSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdf
NourhanTarek23
 
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdfCSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
NourhanTarek23
 
CSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptxCSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptx
NourhanTarek23
 
Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.ppt
NourhanTarek23
 
Lect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.pptLect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.ppt
NourhanTarek23
 
Software engineering.pptx
Software engineering.pptxSoftware engineering.pptx
Software engineering.pptx
NourhanTarek23
 
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives  IOT and Big Data Era.pptxLect01 Computers Impact on Our lives  IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptx
NourhanTarek23
 
section5.pptx
section5.pptxsection5.pptx
section5.pptx
NourhanTarek23
 
Introduction to computer.pptx
Introduction to computer.pptxIntroduction to computer.pptx
Introduction to computer.pptx
NourhanTarek23
 
AOP sec3.pptx
AOP sec3.pptxAOP sec3.pptx
AOP sec3.pptx
NourhanTarek23
 
Introduction to Spring sec2.pptx
Introduction to Spring sec2.pptxIntroduction to Spring sec2.pptx
Introduction to Spring sec2.pptx
NourhanTarek23
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
NourhanTarek23
 
QoS.pptx
QoS.pptxQoS.pptx
QoS.pptx
NourhanTarek23
 
’mobile ip.pptx
’mobile ip.pptx’mobile ip.pptx
’mobile ip.pptx
NourhanTarek23
 
Problem set 3-solution.pptx
Problem set 3-solution.pptxProblem set 3-solution.pptx
Problem set 3-solution.pptx
NourhanTarek23
 

More from NourhanTarek23 (15)

CSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdfCSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdf
 
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdfCSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
 
CSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptxCSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptx
 
Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.ppt
 
Lect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.pptLect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.ppt
 
Software engineering.pptx
Software engineering.pptxSoftware engineering.pptx
Software engineering.pptx
 
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives  IOT and Big Data Era.pptxLect01 Computers Impact on Our lives  IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptx
 
section5.pptx
section5.pptxsection5.pptx
section5.pptx
 
Introduction to computer.pptx
Introduction to computer.pptxIntroduction to computer.pptx
Introduction to computer.pptx
 
AOP sec3.pptx
AOP sec3.pptxAOP sec3.pptx
AOP sec3.pptx
 
Introduction to Spring sec2.pptx
Introduction to Spring sec2.pptxIntroduction to Spring sec2.pptx
Introduction to Spring sec2.pptx
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
 
QoS.pptx
QoS.pptxQoS.pptx
QoS.pptx
 
’mobile ip.pptx
’mobile ip.pptx’mobile ip.pptx
’mobile ip.pptx
 
Problem set 3-solution.pptx
Problem set 3-solution.pptxProblem set 3-solution.pptx
Problem set 3-solution.pptx
 

Lab 7 - Bash Script.pptx

  • 1. Lab 7 – Bash Script CIE 302 - Operating systems
  • 2. What is bash scripting? Bash script: a plain text that contains a series of commands, which can be used to write Linux commands in the terminal. Anything you can run normally on the command line can be put into a script and it will do exactly the same thing. Bash scripts an extension of .sh (myscript.sh). However, Linux is an extensionless system so a script doesn't necessarily have to have this characteristic in order to work.
  • 3. How to execute a bash script?  ./script → it will execute the script file, as a new child process within the bash/terminal.  to grant permissions, to execute file: chmod 755 script1 ⇔ (rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file.
  • 4. Script format #!/bin/bash ⇔ The first line in code, must start with “#!”. # A sample Bash script ⇔ comment line, not executed. echo Hello World! ⇔ actual command that could be directly written in the terminal.
  • 5. Variables To declare a variable: $a, $A, $a1A. To initialize a variable  a=4 To display the variable and its value  echo $a Variable substitution var='Hello Student' text=" $var Ahmed" echo $text
  • 10. Functions To declare a variable: $a, $A, $a1A. To initialize a variable  a=4 To display the variable and its value  echo $a Variable substitution var='Hello Student' text=" $var Ahmed" echo $text