Use when writing shell scripts or working with Bash, Zsh, or POSIX-compatible shells on macOS and Linux. Covers scripting fundamentals, variables, control flow, functions, pipes, process management, and common patterns for automation and developer tooling.
USE FOR: Bash, Zsh, shell scripting, POSIX shell, pipes, redirection, process substitution, shell functions, shell variables, .bashrc, .zshrc, shebang, here documents, command substitution, shell arithmetic
DO NOT USE FOR: PowerShell scripting (use powershell-core), Windows batch files, complex data processing beyond text (consider Python or jq)
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Use when writing shell scripts or working with Bash, Zsh, or POSIX-compatible shells on macOS and Linux. Covers scripting fundamentals, variables, control flow, functions, pipes, process management, and common patterns for automation and developer tooling.
USE FOR: Bash, Zsh, shell scripting, POSIX shell, pipes, redirection, process substitution, shell functions, shell variables, .bashrc, .zshrc, shebang, here documents, command substitution, shell arithmetic
DO NOT USE FOR: PowerShell scripting (use powershell-core), Windows batch files, complex data processing beyond text (consider Python or jq)
[{"title":"GNU Bash Reference Manual","url":"https://www.gnu.org/software/bash/manual/bash.html"},{"title":"Zsh Documentation","url":"https://zsh.sourceforge.io/Doc/"},{"title":"POSIX Shell Command Language Specification","url":"https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html"}]
Bash & Shell Scripting
Overview
Bash is the default shell on most Linux distributions and was the macOS default until Catalina (now Zsh). Shell scripting is the glue that connects CLI tools together and automates repetitive tasks. Most CI/CD pipelines, Docker entrypoints, and deployment scripts are Bash. Understanding shell scripting is a foundational skill for every developer working in Unix-like environments.
Bash vs Zsh vs Fish
Feature
Bash
Zsh
Fish
Compatibility
POSIX
Mostly POSIX
Not POSIX
Default On
Most Linux distros
macOS (Catalina+)
—
Plugin Ecosystem
Minimal
Oh My Zsh / Starship
Built-in
Auto-complete
Basic
Extensive
Excellent, built-in
Scripting
Standard
Bash-compatible + extras
Unique syntax
Tip: Write portable scripts in Bash (or POSIX sh) for maximum compatibility. Use Zsh/Fish features interactively but avoid them in shared scripts.
Fundamentals
Shebang
Every script should start with a shebang line that tells the OS which interpreter to use:
#!/usr/bin/env bash # Portable — finds bash in PATH#!/bin/bash # Absolute path — less portable#!/bin/sh # POSIX shell — most compatible, fewest features
Variables
# Assignment (no spaces around =)
name="world"
count=42
readonly PI=3.14159 # Constant — cannot be reassigned# Usage (always quote to handle spaces/special chars)echo"Hello, ${name}"echo"Count is: $count"# Environment vs localexport GLOBAL_VAR="visible to child processes"
local_var="only in this shell"# Default valuesecho"${MISSING_VAR:-default_value}"# Use default if unsetecho"${MISSING_VAR:=default_value}"# Set and use default if unset
# Iterate over a listfor item in apple banana cherry; doecho"Fruit: $item"done# Iterate over filesfor file in *.txt; doecho"Processing: $file"done# C-style for loopfor ((i = 0; i < 10; i++)); doecho"Index: $i"done# Iterate over command outputfor user in $(cut -d: -f1 /etc/passwd); doecho"User: $user"done
while / until Loops
# while loop
count=0
while [[ $count -lt 5 ]]; doecho"Count: $count"
((count++))
done# until loop (runs until condition is true)until [[ $count -eq 0 ]]; doecho"Countdown: $count"
((count--))
done# Read lines from a filewhile IFS= read -r line; doecho"Line: $line"done < input.txt
ifcommand -v docker &>/dev/null; thenecho"Docker is installed"elseecho"Docker is not installed"exit 1
fi
Conditional Execution
# AND — run second command only if first succeedsmkdir -p build && cd build
# OR — run second command only if first failscommand -v git &>/dev/null || sudo apt install git -y
# Combinedtest -f config.yml && echo"Config found" || echo"Config missing"
sed 's/old/new/' file.txt # Replace first occurrence per line
sed 's/old/new/g' file.txt # Replace all occurrences
sed -i 's/old/new/g' file.txt # Edit file in place
sed -n '10,20p' file.txt # Print lines 10-20
sed '/^#/d' file.txt # Delete comment lines
sed -i.bak 's/old/new/g' file.txt # In-place with backup
# Run a command in the background
long_running_task &
# List background jobsjobs# Bring job to foregroundfg %1
# Send job to backgroundbg %1
# Wait for background processeswait# Wait for allwait$pid# Wait for specific PID# Kill a processkill$pid# Send SIGTERM (graceful)kill -9 $pid# Send SIGKILL (force)kill %1 # Kill job number 1# Run immune to hangupsnohup long_task &> output.log &
# Trap signals for cleanuptrap'echo "Caught SIGINT"; exit 1' INT
trap'cleanup' EXIT TERM