Mission 25 of 30 · Milestone

Shell Scripting Basics

Turn a repeated health-check sequence into an executable script.

Create small Bash scripts inside the sandbox and run them safely.

45–60 min Week 4 · Scripting, scheduling, customization, final project Ubuntu terminal
Your outcome: You can automate repeated steps without touching system files.
Practice inside ~/linux-practice. Check your setup before you begin. Prerequisite: System Monitoring and Performance .

What you’ll practice

  • Create executable scripts
  • Use variables and arguments
  • Understand exit codes

The mental model

  • A shebang tells Linux what interpreter to use.
  • Scripts in ~/linux-practice/scripts are easy to delete later.
  • $? stores the previous command exit code.

Try it in your terminal

Hello script

Safe in practice folder

Creates and runs a first script.

Run from ~/linux-practice

cd ~/linux-practice/scripts
cat << 'EOF' > hello.sh
#!/usr/bin/env bash
echo "Hello, $USER!"
echo "Today is $(date)"
echo "You are in $PWD"
EOF
chmod +x hello.sh
./hello.sh

Arguments script

Safe in practice folder

Shows common script argument variables.

Run from ~/linux-practice

cat << 'EOF' > args.sh
#!/usr/bin/env bash
echo "Script name: $0"
echo "First argument: $1"
echo "All arguments: $@"
echo "Number of arguments: $#"
EOF
chmod +x args.sh
./args.sh one two three

Exit status

Read-only system view

Shows non-zero failure and zero success statuses.

Run from ~/linux-practice

ls /nonexistent
echo "Exit status: $?"
ls /bin/bash
echo "Exit status: $?"

Put it into practice

  1. Write my_first.sh that greets you and lists files in ~/linux-practice.

Check your result

The script runs from its own path and returns a meaningful status.

Milestone challenge

Collect storage, package, connectivity, and health evidence into a timestamped report, then turn the read-only sequence into a reusable script.

Common mistakes

  • You write a perfect script, run `./myscript.sh`, and get 'Permission denied.' The fix: `chmod +x myscript.sh`. You need to tell Linux 'yes, this file is allowed to run as a program.'
  • You create scripts scattered across your home folder and can't find them later. Keep every practice script in `~/linux-practice/scripts/`. One folder, easy to find, easy to delete when you're done.

Check your understanding

Explain these in your own words. If you’re unsure, revisit the examples before moving on.

  1. What is a shebang?
  2. What does chmod +x do?

Your practice, your pace

Loading saved progress…

Discussion

Continue the conversation about this guide. Loading comments connects to GitHub Discussions through giscus.

Open community discussions on GitHub

Check before you copy

This command needs care. Read its context, confirm the target and location, and keep a recovery path.

Copying does not run a command.