DEV Community

Cover image for Basic Bash Scripting
Anthony Reyes
Anthony Reyes

Posted on • Edited on

1

Basic Bash Scripting

Bash is a command language interpreter. It is widely available on various operating systems and is a default command interpreter on most GNU/Linux systems. The name is an acronym for the ‘Bourne-Again SHell’.

Table of Contents

Comments

# Single line comment
: '
This is a
multi line
comment
'
Enter fullscreen mode Exit fullscreen mode

Variables

#!/usr/bin/env bash

NAME="John"
echo "Hello $NAME!"
Enter fullscreen mode Exit fullscreen mode

Functions

get_name() {
  echo "John"
}

echo "You are $(get_name)"
Enter fullscreen mode Exit fullscreen mode

Conditionals

if [[ -z "$string" ]]; then
  echo "String is empty"
elif [[ -n "$string" ]]; then
  echo "String is not empty"
fi
Enter fullscreen mode Exit fullscreen mode

Loops

for i in /etc/rc.*; do
  echo $i
done

for ((i = 0 ; i < 100 ; i++)); do
  echo $i
done

for i in {1..5}; do
    echo "Welcome $i"
done
Enter fullscreen mode Exit fullscreen mode

Execution

Make your bash script executable by running this command.

sudo chmod +x script.sh

./script.sh
Enter fullscreen mode Exit fullscreen mode

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay