Bash scripting
Flow me :
Security test Group on Facebook:
https://www.facebook.com/groups/155349421484222/
On YouTube
https://www.youtube.com/channel/UCpis91Zi0N-CGjqjFXuRt4w
On twitter
https://twitter.com/abdallahelsoka1
Lectured by abdallah elsokary
Echo&printf
#!/bin/bash
Echo “hello world”;
Printf “hello world”;
%s = stirng
%d = integer
Lectured by abdallah elsokary
COMMENTS
#!/bin/bash
#comment
<<comment
some comments
comment
Lectured by abdallah elsokary
VARIABLES
#!/bin/bash
var=“value”
default variables
$hostname
$home
etc….
lectured by abdallah elsokary
VARIABLES
#!/bin/bash
readonly variable
unset variable
Lectured by abdallah elsokary
INPUT
#!/bin/bash
Read –p “your name : ” name
Read –t time
Read –s “your password :” password
Lectured by abdallah elsokary
MATH EXPRESSIONS
#!/bin/bash
number1=15
number2=16
echo $(($number1+$number2))
echo `expr $number1+$number2`
Lectured by abdallah elsokary
#!/bin/bash IF STATMENT
if [condition]; then
“code”
elif [condition]; then
“code”
else
“code”
fi
----------------------------
test condition && ”code” || »code«
lectured by abdallah elsokary
IF STATMENT
#!/bin/bash
Lectured by abdallah elsokary
array
#!/bin/bash
array_name=(value1 space value2)
${array_name[index]}
array_name[0]= »value«
lectured by abdallah elsokary
While loop
#!/bin/bash
a=0
while [ $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
Lectured by abdallah elsokary
Until loop
#!/bin/bash
a=0
until [ ! $a -lt 10 ] do
echo $a
a=`expr $a + 1`
done
Lectured by abdallah elsokary
For loop
#!/bin/bash
for FILE in $HOME/.bash*
do
echo $FILE
done
Lectured by abdallah elsokary
select
#!/bin/bash
Select FILE in $HOME/.bash*
do
echo $FILE
done
Lectured by abdallah elsokary
case
#!/bin/bash
case $DRINK in tea|cofee|water|all)
echo "Go to canteen" ;;
juice|appe)
echo "Available at home" ;; none)
break ;; *)
echo "ERROR: Invalid selection" ;; esac
Lectured by abdallah elsokary
Loop control
#!/bin/bash
Break
Break number
------------------
continue
Lectured by abdallah elsokary
function
#!/bin/bash
number_one ()
{ echo "This is the first function speaking..."
number_two } number_two ()
{ echo "This is now the second function
speaking..." } #
Calling function one. number_one
Lectured by abdallah elsokary
function
#!/bin/bash
number_one ()
{ echo "This is the first function speaking..." number_two
Return 10
} number_two ()
{ echo "This is now the second function speaking..." } #
Calling function one. number_one
Var=$?
Echo var
Lectured by abdallah elsokary
User Administration
#!/bin/bash
/etc/passwd: − Keeps user account and
password information. This file holds the majority
of information about accounts on the Unix
system.
/etc/shadow: − Holds the encrypted password
of the corresponding account. Not all the
system support this file.
/etc/group: − This file contains the group
information for each account.
/etc/gshadow: − This file contains secure group
account information.
Lectured by abdallah elsokary
process
#!/bin/bash
Ps
Ps –f
Full info
Kill –time process id
Lectured by abdallah elsokary