Back to roadmaps shell-script Course

Automating Tasks: Shell Families and Script Basics

Shell scripting allows you to automate repetitive server tasks, deployment pipelines, and file management operations.


1. Bash vs Zsh

The most common Unix shells are Bash (Bourne Again Shell) and Zsh (Z Shell):

  • Bash: The default shell on most Linux servers and older macOS versions. It is the standard for writing portable deployment scripts.
  • Zsh: The default shell on modern macOS (since Catalina). It is more feature-rich for interactive use but maintains Bash compatibility for scripting.

For server-side automation scripts, always write Bash scripts for maximum portability.


2. The Shebang Line

The first line of every shell script must be the shebang (#!). It tells the operating system which interpreter to use to execute the file:

#!/bin/bash
# This is a comment: the rest of the script will be executed by Bash

echo "Hello from my first shell script!"

3. Making Scripts Executable

Shell script files must have the execute permission flag set before you can run them directly:

# Grant execute permission to the script
chmod +x deploy.sh

# Run the script
./deploy.sh

Without chmod +x, you would need to run it as bash deploy.sh explicitly.

Published on Last updated: