| name | bash-scripting |
| description | Bash shell scripting. Use when automating tasks, writing system scripts, or configuring VMs. |
Bash Scripting
Shell scripting for automation and system administration.
Quick Start
#!/bin/bash
set -euo pipefail
echo "Starting VM provisioning..."
Key Patterns
# Variables
VM_NAME="${VM_NAME:-default}"
MEMORY="${MEMORY:-2048}"
# Conditionals
if [[ -f "$disk_image" ]]; then
echo "Disk exists"
fi
# Loops
for vm in vm1 vm2 vm3; do
start_vm "$vm"
done
# Functions
create_disk() {
local name="$1"
local size="$2"
qemu-img create -f qcow2 "${name}.qcow2" "$size"
}
# Arrays
ARGS=(-m 2048 -smp 2 -enable-kvm)
qemu-system-x86_64 "${ARGS[@]}"
Error Handling
set -e # exit on error
trap 'cleanup' EXIT
command -v qemu-system-x86_64 >/dev/null || { echo "QEMU required"; exit 1; }