{"id": "echo-basic", "cmd": "echo hello"} {"id": "printf-args", "cmd": "printf '%s\\n' one two three"} {"id": "pipe-sort", "cmd": "ls | sort"} {"id": "grep-n", "cmd": "cat a.txt | grep -n line"} {"id": "grep-count", "cmd": "grep -c ERROR logs/app.log"} {"id": "redir-in", "cmd": "wc -l < a.txt"} {"id": "redir-out-chain", "cmd": "head -2 data.csv > head.csv && cat head.csv"} {"id": "csv-pipeline", "cmd": "tail -n +2 data.csv | cut -d, -f2 | sort | uniq -c | sort -rn"} {"id": "arith", "cmd": "x=5; y=7; echo $((x*y+1))"} {"id": "for-loop", "cmd": "for i in 1 2 3; do echo \"i=$i\"; done"} {"id": "while-loop", "cmd": "i=0; while [ $i -lt 3 ]; do echo loop $i; i=$((i+1)); done"} {"id": "until-loop", "cmd": "i=3; until [ $i -le 0 ]; do echo down $i; i=$((i-1)); done"} {"id": "if-file", "cmd": "if [ -f a.txt ]; then echo yes; else echo no; fi"} {"id": "case", "cmd": "case \"abc\" in a*) echo starts-a;; *) echo other;; esac"} {"id": "func-basic", "cmd": "f() { echo \"fn:$1\"; }; f world"} {"id": "func-local", "cmd": "greet() { local n=\"$1\"; echo \"hi $n\"; }; greet nash"} {"id": "and-or", "cmd": "echo one && echo two || echo three"} {"id": "or-fallback", "cmd": "false || echo fallback"} {"id": "and-ok", "cmd": "true && echo ok"} {"id": "subshell-cd", "cmd": "(cd src && pwd | xargs basename)"} {"id": "param-default", "cmd": "VAR=hello; echo \"${VAR:-default} ${UNSET:-default}\""} {"id": "param-strip", "cmd": "s=\"filename.tar.gz\"; echo \"${s%.gz} ${s%%.*} ${s#file}\""} {"id": "param-replace-len", "cmd": "s=\"hello world\"; echo \"${s/world/nash} ${#s}\""} {"id": "brace-expand", "cmd": "echo {a,b,c}{1,2}"} {"id": "glob-txt", "cmd": "ls *.txt | sort"} {"id": "array-basic", "cmd": "arr=(x y z); echo \"${arr[1]} ${#arr[@]} ${arr[@]}\""} {"id": "awk-sum", "cmd": "seq 1 5 | awk '{s+=$1} END {print s}'"} {"id": "sed-print", "cmd": "sed -n '2p' a.txt"} {"id": "sed-file-out", "cmd": "sed 's/line/LINE/g' a.txt > upper.txt; wc -l upper.txt"} {"id": "sort-uniq", "cmd": "sort b.txt | uniq | head -3"} {"id": "cut-tr", "cmd": "cut -d, -f1 data.csv | tr 'a-z' 'A-Z' | tail -2"} {"id": "find-name", "cmd": "find . -name '*.py' | sort"} {"id": "find-exec", "cmd": "find src -type f -name '*.py' -exec wc -l {} + | sort -k2"} {"id": "tr-wc", "cmd": "echo \"a b c\" | tr ' ' '\\n' | wc -l"} {"id": "heredoc-expand", "cmd": "cat < out.txt; echo again >> out.txt; cat out.txt"} {"id": "redir-stderr-file", "cmd": "ls missing-dir 2> err.txt; test -s err.txt && echo captured"} {"id": "stderr-to-pipe", "cmd": "ls missing-dir 2>&1 | grep -o 'No such file or directory'"} {"id": "brace-group-redir", "cmd": "{ echo brace1; echo brace2; } > group.txt; cat group.txt"} {"id": "subshell-simple", "cmd": "(echo subshell) && echo after"} {"id": "cmdsub-nested", "cmd": "echo $(echo nested $(echo deeper))"} {"id": "cmdsub-multiline", "cmd": "files=$(ls *.txt | sort | head -2); echo \"$files\" | wc -l"} {"id": "cmdsub-grep", "cmd": "n=$(grep -c INFO logs/app.log); echo \"count=$n\""} {"id": "basename-pwd", "cmd": "echo \"$(basename \"$PWD\")\""} {"id": "set-e-false", "cmd": "set -e; false; echo unreachable"} {"id": "set-e-true", "cmd": "set -e; true; echo reached"} {"id": "pipefail", "cmd": "set -o pipefail; false | true; echo \"code=$?\""} {"id": "yes-head", "cmd": "yes | head -3"} {"id": "read-loop", "cmd": "printf 'a\\nb\\n' | while read l; do echo \"got:$l\"; done"} {"id": "exit-code", "cmd": "echo start; exit 3"} {"id": "child-bash", "cmd": "bash -c 'echo child'"} {"id": "command-v", "cmd": "command -v ls > /dev/null && echo has-ls"} {"id": "type-t", "cmd": "type -t ls"} {"id": "cond-pattern", "cmd": "[[ \"abc\" == a?c ]] && echo pattern-match"} {"id": "cond-numeric", "cmd": "[[ \"5\" -gt 3 ]] && echo gt"} {"id": "test-dir", "cmd": "test -d src && echo isdir"} {"id": "echo-n", "cmd": "echo -n \"no-newline\"; echo \"|end\""} {"id": "printf-pad", "cmd": "printf '%05d\\n' 42"} {"id": "ifs-split", "cmd": "IFS=,; set -- a,b,c; echo $1"} {"id": "glob-all", "cmd": "echo *"} {"id": "ls-dir", "cmd": "ls -1 src/"} {"id": "mkdir-touch-find", "cmd": "mkdir -p deep/nested/dir && touch deep/nested/dir/f.txt && find deep -type f"} {"id": "cp-diff", "cmd": "cp a.txt copy.txt && diff a.txt copy.txt && echo identical"} {"id": "mv-ls", "cmd": "mv b.txt moved.txt && ls moved.txt"} {"id": "rm-check", "cmd": "cp a.txt c2.txt && rm c2.txt && ls c2.txt 2>/dev/null; echo \"gone rc=$?\""} {"id": "background-wait", "cmd": "(sleep 0.1; echo bg) & wait; echo done"} {"id": "procsub-diff", "cmd": "diff <(echo a) <(echo a) && echo same"} {"id": "procsub-comm", "cmd": "comm -12 <(printf '1\\n2\\n3\\n') <(printf '2\\n3\\n4\\n')"} {"id": "export-child", "cmd": "export FOO=bar; bash -c 'echo $FOO'"} {"id": "xargs-n1", "cmd": "printf 'a b c' | xargs -n1 echo"} {"id": "awk-begin", "cmd": "awk 'BEGIN{printf \"%.2f\\n\", 10/3}'"} {"id": "python-child", "cmd": "python3 -c 'print(6*7)'"} {"id": "node-child", "cmd": "node -e 'console.log(\"js\")'"} {"id": "tar-roundtrip", "cmd": "tar -czf arch.tgz src && tar -tzf arch.tgz | sort"} {"id": "tee-multi", "cmd": "echo 'x' | tee t1.txt t2.txt && cat t1.txt t2.txt"} {"id": "trap-exit", "cmd": "trap 'echo trapped' EXIT; echo body"} {"id": "quoting-mixed", "cmd": "printf '%s\\n' \"double \\\"quoted\\\" and 'single'\""} {"id": "escapes", "cmd": "echo \"backslash: \\\\ dollar: \\$HOME\""} {"id": "line-continuation", "cmd": "echo one \\\ntwo"} {"id": "func-return", "cmd": "f(){ return 4; }; f; echo \"rc=$?\""} {"id": "shift-args", "cmd": "set -- a b c; shift; echo \"$1 $#\""} {"id": "getopts", "cmd": "f() { while getopts 'x:y' o; do echo \"o=$o a=$OPTARG\"; done; }; f -x val -y"} {"id": "declare-i", "cmd": "declare -i n=5; n+=2; echo $n"} {"id": "dirname-basename", "cmd": "dirname src/main.py; basename src/main.py .py"} {"id": "realpath", "cmd": "realpath a.txt"} {"id": "stat-size", "cmd": "stat -c %s a.txt"} {"id": "od-herestring", "cmd": "od -c <<< 'hi' | head -1"} {"id": "dev-null", "cmd": "echo discarded > /dev/null; echo kept"} {"id": "fd-dup-order", "cmd": "{ echo to-out; echo to-err >&2; } 2>/dev/null"} {"id": "curl-sh-shape", "cmd": "printf 'echo piped-script\\n' | bash"} {"id": "seq-paste", "cmd": "seq 1 4 | paste -sd+ | bc 2>/dev/null || seq 1 4 | paste -sd,"} {"id": "nested-quotes-cmdsub", "cmd": "echo \"outer $(echo \"inner $(echo deepest)\")\""} {"id": "utf8-read-passthru", "cmd": "printf 'F\\305\\221tan\\303\\272s\\303\\255tv\\303\\241ny\\n' | { read x; printf '%s\\n' \"$x\"; }"} {"id": "utf8-while-read-file", "cmd": "printf 'caf\\303\\251.crt\\nna\\303\\257ve.pem\\n' > names.txt; while read n; do echo \"got:$n\"; done < names.txt"} {"id": "utf8-cmdsub-roundtrip", "cmd": "x=$(printf '\\303\\251l\\303\\251gant'); echo \"$x\""} {"id": "errexit-if-andlist", "cmd": "set -e; if true; then false && true; fi; echo survived"} {"id": "errexit-brace-andlist", "cmd": "set -e; { false && true; }; echo grouped-ok"} {"id": "errexit-if-bang", "cmd": "set -e; if true; then ! true; fi; echo bang-ok"} {"id": "errexit-fn-status", "cmd": "set -e; f() { false && true; }; f && echo unreachable || echo fn-failed"}