📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Linux Command Line Shell Scripting Basics

Shell Scripting Basics

6 min read Quiz at the end
Shell scripts automate tasks. Start with #!/bin/bash and add set -euo pipefail to exit on errors. Make executable with chmod +x script.sh. Use variables, if conditions, and loops just like a programming language.

Writing Shell Scripts

#!/bin/bash
# backup.sh

SOURCE="/var/www"
DEST="/backup/$(date +%Y%m%d)"

mkdir -p "$DEST"
cp -r "$SOURCE" "$DEST"
echo "Backup done: $DEST"
chmod +x backup.sh
./backup.sh
Topic Quiz · 5 questions

Test your understanding before moving on

1. What is the shebang line?
💡 #!/bin/bash (or #!/usr/bin/env bash) tells the OS which interpreter to use.
2. How do you make a script executable?
💡 chmod +x script.sh adds execute permission so you can run it.
3. How do you run a script?
💡 ./script.sh runs the script from the current directory.
4. What does $1 mean in a script?
💡 $1 is the first positional argument: ./script.sh arg1 → $1 = "arg1".
5. $@ in a script means:
💡 $@ expands to all positional arguments as separate words.