เชฎเซเช–เซเชฏ เชธเชพเชฎเช—เซเชฐเซ€ เชชเชฐ เชœเชพเช“
JobCannon
เชฌเชงเชพ เช•เซŒเชถเชฒเซเชฏเซ‹

Shell Scripting

Automate everything with Bash, Zsh, and command-line tools

โฌข เชŸเชฟเชฏเชฐ 2เชŸเซ‡เช•เชจเชฟเช•เชฒ
เชฎเชงเซเชฏเชฎ
เชชเช—เชพเชฐ เชชเชฐ เช…เชธเชฐ
2 เชฎเชนเชฟเชจเชพ
เชถเซ€เช–เชตเชพเชจเซ‹ เชธเชฎเชฏ
เชฎเชงเซเชฏเชฎ
เชฎเซเชถเซเช•เซ‡เชฒเซ€
1
เช•เชฐเชฟเชฏเชฐ
เชเช• เชจเชœเชฐเชฎเชพเช‚

Shell scripting (Bash, Zsh, POSIX sh) automates deployment, configuration, and operational tasks across Unix/Linux systems. Supplementary skill that unlocks senior DevOps and SRE roles: junior uses scripts for basic automation (+$10-15k), mid-level orchestrates complex pipelines with sed/awk/jq (+$15-20k), senior tunes performance and writes portable frameworks (+$20-25k). Prerequisite for backend/DevOps tier advancement. Time investment: 1-3 months for proficiency. Tools: bash, zsh, sed, awk, grep, find, xargs, jq, ShellCheck. Not a primary career path (unlike programming languages), but mandatory foundation.

Shell Scripting เชถเซเช‚ เช›เซ‡

  • Shell scripts being replaced by Python for complex logic - ShellCheck and shfmt standardizing script quality

๐Ÿ”ง เชŸเซ‚เชฒเซเชธ เช…เชจเซ‡ เช‡เช•เซ‹เชธเชฟเชธเซเชŸเชฎ
bashzshPOSIX shsedawkgrepfindxargsjqShellCheckfishcurl

๐Ÿ“‹ เชคเชฎเซ‡ เชถเชฐเซ‚ เช•เชฐเซ‹ เชคเซ‡ เชชเชนเซ‡เชฒเชพเช‚

๐Ÿ’ฐ เชชเซเชฐเชฆเซ‡เชถ เชชเซเชฐเชฎเชพเชฃเซ‡ เชชเช—เชพเชฐ

เชชเซเชฐเชฆเซ‡เชถเชœเซเชจเชฟเชฏเชฐเชฎเชงเซเชฏเชฎเชธเชฟเชจเชฟเชฏเชฐ
USA$85k$115k$160k
UKยฃ52kยฃ70kยฃ98k
EUโ‚ฌ58kโ‚ฌ78kโ‚ฌ110k
CANADAC$88kC$120kC$168k

๐ŸŽฏ Shell Scripting เชจเซ‹ เช‰เชชเชฏเซ‹เช— เช•เชฐเชคเซ€ เช•เชฐเชฟเชฏเชฐ

โš– เชธเชพเชฅเซ‡ เชธเชฐเช–เชพเชฎเชฃเซ€ เช•เชฐเซ‹

โ“ FAQ

Bash vs Zsh, which should I learn?
Bash: 30+ years, universal (ships on every Unix/Linux/Mac), POSIX-compatible, scripts run everywhere. Zsh: modern, interactive features (completion, history), friendly syntax. Learn Bash first for portability and career breadth, it's the standard for deployment scripts and cron jobs. Zsh after, for your personal shell. Write production scripts in Bash, interactive shell in Zsh. Zsh on macOS is now default, but servers still run Bash.
When should I use Python instead of shell scripts?
Use shell for: file operations, tool orchestration, simple data pipelines, deployment steps, cron jobs, quick 10-50 line tasks. Use Python for: complex logic, data structures, unit testing, maintenance >1000 lines, portability across OS (Windows, macOS, Linux), dependency management. Rule: if your script needs classes, error handling beyond `set -e`, or complex iteration, switch to Python. If it's gluing tools together, stay in shell.
How do I handle errors properly in shell scripts?
Start every script with `set -euo pipefail`: -e stops on error, -u errors on undefined vars, -o pipefail fails if any pipe stage fails. Use functions with explicit return codes. Trap errors: `trap 'echo Error at line $LINENO' ERR`. Quote all variables: `"$var"` not `$var`. Test edge cases: empty input, special characters, large files. Use ShellCheck (`shellcheck script.sh`) to catch common mistakes before runtime.
What does ShellCheck do and why should I use it?
ShellCheck is a linter that finds bugs and portability issues before runtime. It catches: unquoted vars, unreachable code, deprecated syntax, inefficient patterns. Run on every script: `shellcheck myscript.sh`. Integrates with editors (VSCode ShellCheck extension). Warnings = code smell, errors = bugs. Passing ShellCheck is non-negotiable for production scripts. Disable warnings sparingly (`# shellcheck disable=SC2086`) only when you understand the risk.
How do dotfiles work and should I version control them?
Dotfiles (.bashrc, .zshrc, .config/) are shell config and environment setup. Version control them in a git repo (with a README explaining symlinks or bootstrap script). Symlink into home: `ln -s ~/dotfiles/.bashrc ~/.bashrc`. Benefits: reproducible environment, share across machines, collaborate with team. Never hardcode secrets (use .env or `pass` password manager). Popular pattern: `~/dotfiles/install.sh` creates symlinks, runs once per machine.
What are common pitfalls and how do I avoid them?
Pitfall 1: Not quoting variables, causes word splitting and globbing. Fix: `"$var"` always. Pitfall 2: Using `ls` in scripts, parsing output fails with spaces. Fix: use glob patterns or `find`. Pitfall 3: Parsing JSON/YAML with regex, fragile. Fix: use `jq` (JSON) or `yq` (YAML). Pitfall 4: Hardcoding paths, breaks on different systems. Fix: use `$HOME`, `readlink -f`, or relative paths. Pitfall 5: No error context, hard to debug. Fix: add logging and use `PS4` for trace output.
How do I make my shell scripts portable across systems?
Write POSIX-compliant code, not Bash-only. Use `#!/bin/sh` not `#!/bin/bash` when possible. Avoid: `[[]]` (use `[]`), `=~` regex (use `grep`), arrays (use loops). Check syntax: `sh -n script.sh`. Test on multiple systems (Mac, Linux, BSD). Use `env bash` in shebang if Bash required. Document dependencies (jq, curl, awk version). Use `command -v` to check if tools exist before using. Ship with `install.sh` that checks requirements.

เช–เชพเชคเชฐเซ€ เชจเชฅเซ€ เช•เซ‡ เช† เช•เซŒเชถเชฒเซเชฏ เชคเชฎเชพเชฐเชพ เชฎเชพเชŸเซ‡ เช›เซ‡?

เช•เชฐเชฟเชฏเชฐ เชฎเซ‡เชš เชŸเซ‡เชธเซเชŸ เช†เชชเซ‹ โ€” เช…เชฎเซ‡ เชฏเซ‹เช—เซเชฏ เชŸเซเชฐเซ‡เช•เซเชธ เชธเซ‚เชšเชตเซ€เชถเซเช‚.

เชฎเชพเชฐเชพ เชถเซเชฐเซ‡เชทเซเช -เชซเชฟเชŸ เช•เซŒเชถเชฒเซเชฏเซ‹ เชถเซ‹เชงเซ‹ โ†’

เชคเชฎเชพเชฐเซ‹ เช†เชฆเชฐเซเชถ เช•เชฐเชฟเชฏเชฐ เชชเชพเชฅ เชถเซ‹เชงเซ‹

2,521 เช•เชพเชฐเช•เชฟเชฐเซเชฆเซ€เช“เชฎเชพเช‚ เช•เซŒเชถเชฒเซเชฏ-เช†เชงเชพเชฐเชฟเชค เชฎเซ‡เชšเชฟเช‚เช—. เชฎเชซเชค.

เช•เชฐเชฟเชฏเชฐ เชฎเซ‡เชš เชŸเซ‡เชธเซเชŸ เช†เชชเซ‹ โ€” เชฎเชซเชค โ†’