Install
openclaw skills install bashWrite reliable Bash scripts with proper quoting, error handling, and parameter expansion.
openclaw skills install bash| Topic | File |
|---|---|
| Arrays and loops | arrays.md |
| Parameter expansion | expansion.md |
| Error handling patterns | errors.md |
| Testing and conditionals | testing.md |
"$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 formatting