Bash
Avoid common Bash mistakes — quoting traps, word splitting, and subshell gotchas.
New
Join 0+ developers using this skill
skill
Development & Code Tools
intermediate
Avoid common Bash mistakes — quoting traps, word splitting, and subshell gotchas.
Real data. Real impact.
Emerging
Developers
Per week
Open source
Skills give you superpowers. Install in 30 seconds.
| Topic | File |
|---|---|
| Arrays and loops | |
| Parameter expansion | |
| Error handling patterns | |
| Testing and conditionals | |
"$var" not $var, spaces break unquoted"${arr[@]}" preserves elements—${arr[*]} joins into single string'$var' doesn't expand"$(command)" not $(command)$var splits on whitespace—file="my file.txt"; cat $file fails* expands to files—quote or escape if literal: "*" or \*set -f disables globbing—or quote everything properly[[ ]] preferred over [ ]—no word splitting, supports &&, ||, regex[[ $var == pattern* ]]—glob patterns without quotes on right side[[ $var =~ regex ]]—regex match, don't quote the regex-z is empty, -n is non-empty—[[ -z "$var" ]] tests if emptycat file | while read; do ((count++)); done—count lostwhile read < file or process substitution—while read; do ...; done < <(command)( ) is subshell, { } is same shell—variables in ( ) don't persistset -e exits on error—but not in if, ||, && conditionsset -u errors on undefined vars—catches typosset -o pipefail—pipeline fails if any command fails, not just lasttrap cleanup EXIT—runs on any exit, even errorsarr=(one two three)—or arr=() then arr+=(item)${#arr[@]}—not ${#arr}"${arr[@]}"—always quote${!arr[@]}—useful for sparse arrays${var:-default}—use default if unset/empty${var:=default}—also assigns to var${var:?error message}—exits with message${var:0:5}—first 5 chars${var#pattern}—## for greedy$(( )) for math—result=$((a + b))(( )) for conditions—if (( count > 5 )); then$ needed inside $(( ))—$((count + 1)) not $(($count + 1))[ $var = "value" ] fails if var empty—use [ "$var" = "value" ] or [[ ]]if [ -f $file ] with spaces—always quote: if [[ -f "$file" ]]local in functions—without it, variables are globalread without -r—backslashes interpreted as escapesecho portability—use printf for reliable formattingNo automatic installation available. Please visit the source repository for installation instructions.
View Installation Instructions1,500+ AI skills, agents & workflows. Install in 30 seconds. Part of the Torly.ai family.
© 2026 Torly.ai. All rights reserved.