Skip to main content

Shell Scripting Tutorial: Bash for DevOps

Learn Bash shell scripting for DevOps from zero: variables, loops, functions, error handling, cron, APIs and AWS CLI, with three real projects.

Prerequisites
~2.5 hours
14 Topics
Hands-on Scenarios

What You'll Learn

Understanding Why Shell Scripting Matters

Friday, 6:15 PM. Release night. The deploy runbook has 14 manual steps, and it has to be run on six servers.

Setting Up and Running Your First Script

How do you get a practice environment? Any Linux machine works: WSL2 on Windows, a Multipass or VirtualBox VM, or a small cloud server such as an EC2...

Working with Variables, Input and Arguments

How do you create and use variables? A variable is a named value. Assign with name=value and no spaces around =; read it with $name or ${name}.

Making Decisions with Conditionals

How do exit codes drive every decision? Every command finishes with an exit code: 0 means success, anything from 1 to 255 means some kind of failure.

Repeating Work with Loops

How do for loops work? A for loop runs a block once per item in a list.

Building Reusable Functions

How do you define and call functions? A function is a named block of commands you can run many times, like a mini-script inside your script.

Skills You'll Master

BASHSHELL-SCRIPTINGAUTOMATIONLINUXCRON-JOBS

Curriculum Index14 topics

1

Understanding Why Shell Scripting Matters

Friday, 6:15 PM. Release night. The deploy runbook has 14 manual steps, and it has to be run on six servers.

2

Setting Up and Running Your First Script

How do you get a practice environment? Any Linux machine works: WSL2 on Windows, a Multipass or VirtualBox VM, or a...

3

Working with Variables, Input and Arguments

How do you create and use variables? A variable is a named value.

4

Making Decisions with Conditionals

How do exit codes drive every decision? Every command finishes with an exit code: 0 means success, anything from 1 to...

5

Repeating Work with Loops

How do for loops work? A for loop runs a block once per item in a list.

6

Building Reusable Functions

How do you define and call functions? A function is a named block of commands you can run many times, like a...

7

Handling Data with Arrays, Strings and Here Documents

How do indexed arrays work? An indexed array holds an ordered list of values, numbered from 0.

8

Controlling Input, Output and Text Processing

How does redirection work? Every command has three streams: stdin (0, input), stdout (1, normal output) and stderr (2...

9

Writing Robust Scripts and Debugging Them

What does set -euo pipefail do? By default Bash keeps going after errors, uses empty strings for typos in variable...

10

Managing Processes, Services and Schedules

How do you run jobs in the background and in parallel?

11

Automating System Health, Storage and Logs

How do you monitor CPU, memory and processes in a script?

12

Integrating APIs, AWS CLI and CI/CD

How do you call APIs with curl and wget? curl sends HTTP requests and is the standard tool for health checks, webhooks...

13

Building Three Real Projects Hands-On

What will you build in these projects? You will build three scripts used on real teams.

14

Troubleshooting Scripts with a Quick Reference

How do you fix the most common script errors?

Career Impact

Roles that use the skills in this module.

  • Automation Engineer

    ₹5L - ₹12L a year

    Very High
  • DevOps Engineer

    ₹8L - ₹18L a year

    High Demand
  • Systems Engineer

    ₹6L - ₹14L a year

    High Demand
See how this is asked in interviews

Practice on the Coding Sheet

Not a software engineer sheet. Every problem comes from real DevOps, SRE, Platform and Cloud interviews, from your first script to a system you build yourself.

Open the Coding Sheet

Frequently Asked Questions

Yes. Every CI/CD pipeline step, Dockerfile RUN line, cron job and server bootstrap script is shell. Even teams that use Python, Ansible and Terraform rely on Bash as the glue between tools, so it is one of the first automation skills interviewers check.

Learn both, for different jobs. Bash is best for short scripts that run commands, move files and glue tools together. Switch to Python when a script needs complex data structures, heavy JSON handling, unit tests or grows beyond a couple of hundred lines.

sh is the original minimal POSIX shell, and on many systems it is actually a smaller shell like dash. Bash is a superset with arrays, [[ ]] tests, better string handling and more. Start scripts with a Bash shebang if you use any Bash features.

Run bash -n script.sh to check syntax without executing, then bash -x script.sh to print every command as it runs. Add set -euo pipefail at the top so errors stop the script immediately, and run ShellCheck to catch common bugs before they reach production.