Skip to Content

Bash Shell Scripting -headlines-

Conceptor's picture

What is the comment, why and how? How can I make my script receive arguments? How to execute scripts ?

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

echo " the value is $value " echo ' the value is $vale '
  1. they are different.
  2. How to skip special chracters ? Using ' ' or using backslash .

    1. note : how ` and ' are different this …GRR
    Var=`du –s /home/sakia | cut –f 1 ` echo "the sakia using /home/sakia $Var kilobytes"
    1. think about this how can I use environment #variables here echo " the $USER using /home/sakia $Var Kilobytes"
      1. it is a challenge sequence to make the script
      2. for generic use as it asks u to enter the home
      3. directory of the desired home dir.

        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

        1. !/bin/bash String1="Egypt linux User's Group"; String2="EGLUG"; then echo "first string equals the next"; else echo "they are not equal " fi 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; then echo "num1 is greater than num2"; else echo " num2 is greater than num1"; fi let num4=$num1+$num2; 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 then echo "$file is executable "; else echo "$file is not executable "; fi then echo "$file is directory "; else echo "$file is not directory "; #it may be link or device . fi then echo "$dir1 is readable and executable "; else echo "$dir1 is not both readable and executable"; fi



Dr. Radut | blog