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.
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
Hello script
Creates and runs a first script.
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.shArguments script
Shows common script argument variables.
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 threeExit status
Shows non-zero failure and zero success statuses.
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?