Bash Shell Scripting -headlines-
What is the comment, why and how? How can I make my script receive arguments? How to execute scripts ?
$ bash script_name
$ ./script_name –where pwd=./
What is variable? Is there any Special variables? How and why ?
Notes :
Double (") and single (') quotes behave differently Do not confuse the backtick (`) with single quotes
var1="value" echo " the value is $value " echo ' the value is $vale '
- they are different.
How to skip special chracters ? Using ' ' or using backslash .
Var=`du –s /home/sakia | cut –f 1 ` echo "the sakia using /home/sakia $Var kilobytes"
- note : how ` and ' are different this …GRR
- think about this how can I use environment #variables here echo " the $USER using /home/sakia $Var Kilobytes"
- it is a challenge sequence to make the script
- for generic use as it asks u to enter the home
- directory of the desired home dir.
- it may notify u if the user is exist on ur machine or not . check the /etc/passwd
It may be easy if we continuo the session
Intorduaction to IF statement There is 4 operations which is equal "=" ,
not equal "!=" ,
non-zero length "–n"
and zero-length "–z"
Start new script
- !/bin/bash String1="Egypt linux User's Group"; String2="EGLUG"; if "$String1 = $String2 " then echo "first string equals the next"; else echo "they are not equal " fi if "-n $String1 " then echo " string is not empty ,which is $String1 "; else echo " string is empty "; fi
If operation for numerical comparisons "-eg" equal , "-ne" not equal , "-gt" greater than ,"-ge" greater than or equal , "-lt" less than and "le" less or equal .
Start new script
num1=10; num2=15; num3=20; if $num1 –ge $num2 then echo "num1 is greater than num2"; else echo " num2 is greater than num1"; fi let num4=$num1+$num2; if $num4 –gt $num3 then echo "$num4 is greater than $num3"; else echo "$num4 is less than or equal to num3"; fi
If condition for files and directories. Operation for file comparisons -d the file is directory
-f the file is regular file 3adey ya 3aney
-r is read permission set
-w is write permission set
-x is executable permission set
-s is there any non empty file
dir1=/home/sakia; file1=/home/sakia/test if -x $file1 then echo "$file is executable "; else echo "$file is not executable "; fi if -d $file1 then echo "$file is directory "; else echo "$file is not directory "; #it may be link or device . fi if -r -$dir1 –a –x $dir1 then echo "$dir1 is readable and executable "; else echo "$dir1 is not both readable and executable"; fi
- Conceptor's blog
- Login or register to post comments
- 2496 reads

