Skip to content
Learn Netverks

Lesson

Step 18/36 50% through track

scripts-bash

Bash scripts

Last reviewed May 28, 2026 Content v20260528
Track mode
none
Means
Read / quiz
Reading
~2 min
Level
beginner

This lesson

This lesson teaches Bash scripts: the syntax, patterns, and safety habits you need before advancing in Bash.

Teams still ship Bash scripts in Bash codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Bash scripts in contexts like: Batch jobs, log capture, and repeatable deploy scripts checked into Git.

Read each lesson, copy bash examples into your own terminal, and complete the lesson MCQs—there is no in-browser runner for security reasons.

When you can explain the previous lesson's ideas without copying starter code.

A script is a text file with a shebang and shell commands. Scripts make repeatable what you would otherwise retype—deploy steps, backups, and local dev setup.

Minimal script structure

#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
echo "Starting deploy..."
echo "Done."

set -euo pipefail is a common safety trio: exit on error, error on unset vars, fail pipelines on first error.

Running scripts

./deploy.sh          # needs execute bit
bash deploy.sh       # runs with bash even without +x

Prefer explicit bash script.sh in docs when execute bit might be missing.

Debugging

bash -x deploy.sh    # trace each command
set -x               # enable tracing inside script
set +x               # disable tracing

Tracing helps debug CI failures—compare with logs from Git CI lessons later.

Important interview questions and answers

  1. Q: What does set -e do?
    A: Exit immediately if a command returns non-zero (with exceptions for some contexts).
  2. Q: bash script.sh vs ./script.sh?
    A: The former needs no execute bit; the latter requires +x and honors shebang.

Self-check

  1. Name three flags in the safety trio set -euo pipefail.
  2. What flag prints commands as they run?

Tip: Start serious scripts with set -euo pipefail and a comment describing required tools.

Interview prep

set -e?

Exit script when a command fails.

bash -x?

Print commands before execution (trace).

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • shebang #!/bin/bash?
  • set -u habit?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump