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.
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 folderCreates 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 folderShows 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 viewShows 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
- 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.
- What is a shebang?
- What does chmod +x do?
Your practice, your pace
Loading saved progress…