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

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

👋 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