Intro to bash

Bash is a shell, or commend language interpreter, for the GNU operating system

Example. $USER and $PWD are variables

  • echo “print” # to print something
val=1
val=$((val+1)) # it increases the value by 1
  • We can use let val+=1 to increase its value
fix=2
for ((i = 1; i <= 99; i++)) 
do
    if [ $((i%fix)) -eq 1 ] 
    then
        echo "Number: $i"
    fi
done

output: 1, 3, 5, 7, 9, 11, ....., 99
  • read is used to take input

  • Comparing numbers:

      read X
      read Y
    
      if [ $X -lt $Y ] ; 
      then
          echo "X is less than Y"
      elif [ $X -gt $Y ] ;
      then
          echo "X is greater than Y"
      else
          echo "X is equal to Y"
          fi
    
  • Comparing multiple conditions:

read c
if [[ c=="Y" || c=="y" ]]
then
    echo "YES"
else 
    echo "NO"
    fi
0
Subscribe to my newsletter

Read articles from Ashish prajapati directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ashish prajapati
Ashish prajapati

I am a front-end web developer and currently exploring new things about backend development