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

05 - Module 5 - Bash Scripting

This document provides an overview of Bash scripting including: 1) Introducing variables, input/output, if/else/elif statements, loops, functions and practical examples. 2) Variables can be set and unset, command substitution uses backticks, and arguments are referenced as $0, $1, etc. 3) If/else/elif statements use syntax with square brackets to test conditions and execute different blocks of code.

Uploaded by

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

05 - Module 5 - Bash Scripting

This document provides an overview of Bash scripting including: 1) Introducing variables, input/output, if/else/elif statements, loops, functions and practical examples. 2) Variables can be set and unset, command substitution uses backticks, and arguments are referenced as $0, $1, etc. 3) If/else/elif statements use syntax with square brackets to test conditions and execute different blocks of code.

Uploaded by

Ahmed Marzouq
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

5.

Bash Scripting

• Intro to Bash Scripting

• Variables, Input

• If, Else, Elif Statements

• Boolean Logical Operations

• Loops

• Functions

• Practical Examples
Intro to Bash Scripting

• Begin with #!/bin/bash

• Must have executable permissions set before they can be executed


Variables

• how to set , unset them

• Command substitution using 'backtick


• ❯ File_count=`ls | wc`

• ❯ testing=`date`

• ❯ A=`cat /etc/passwd | head -n1`

• Arguments "$0,$1,$2….."
If, Else, Elif Statements

• Syntax
if [ <some test> ]
then
< commands >
elif [ <some test> ]
then
< different commands >
else
< Other commands >
fi
Boolean Logical Operations
Loops

• for var-name in <list>


do
<action to perform>
Done

• while [ <some test> ]


do
<perform an action>
done
Functions

• Syntax:
function_name () {
commands
}
• OR:
function_name () {commands;}
• Call:
function_name
Practical Examples

You might also like