DEV Community

Ashish Prajapati
Ashish Prajapati

Posted on

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
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode
  • Comparing multiple conditions:
read c
if [[ c=="Y" || c=="y" ]]
then
    echo "YES"
else 
    echo "NO"
    fi
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay