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

Lab 7 - Bash Script

The document discusses bash scripting in Linux. Bash scripts allow a series of commands to be executed from a plain text file rather than typing them individually in the terminal. They have a .sh extension and are executed using ./script. Scripts start with a shebang line (!#/bin/bash) and can include commands, variables, conditional statements like if/else, and loops. Variables are declared with a $ and initialized with an equals sign. Functions can also be defined to group common commands.

Uploaded by

Nourhan Tarek
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views

Lab 7 - Bash Script

The document discusses bash scripting in Linux. Bash scripts allow a series of commands to be executed from a plain text file rather than typing them individually in the terminal. They have a .sh extension and are executed using ./script. Scripts start with a shebang line (!#/bin/bash) and can include commands, variables, conditional statements like if/else, and loops. Variables are declared with a $ and initialized with an equals sign. Functions can also be defined to group common commands.

Uploaded by

Nourhan Tarek
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

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

You might also like