Suggested day 2520–30 minutesSafe in practice folder Module milestone

Mission 5 of 5

Shell Scripting Basics

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

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

Outcome: You can automate repeated steps without touching system files.

Mental model

Understand what is happening

A shebang tells Linux what interpreter to use.

Scripts in ~/linux-practice/scripts are easy to delete later.

$? stores the previous command exit code.

Guided lab

Work through the mission

1

Hello script

Safe

Creates and runs a first script.

Terminal
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
2

Arguments script

Safe

Shows common script argument variables.

Terminal
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
3

Exit status

Read-only

Shows non-zero failure and zero success statuses.

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

Checkpoint

Verify the mission

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

Try it yourself

One step without a recipe

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

Need a hint?

Start Bash scripts with `#!/usr/bin/env bash`. Consider `set -e` only after learning its edge cases; explicit checks and clear error messages are easier to reason about in beginner scripts.

Explain it back

Before you move on

  • What is a shebang?
  • What does chmod +x do?

Shortcuts:Alt + ← previous lessonAlt + → next lessonAlt + H home? focus search