$ curl cheat.sh/
{"topic": "bash", "answer": "# To implement a for loop:\nfor file in *;\ndo \n    echo $file found;\ndone\n\n# To implement a case command:\ncase \"$1\"\nin\n    0) echo \"zero found\";;\n    1) echo \"one found\";;\n    2) echo \"two found\";;\n    3*) echo \"something beginning with 3 found\";;\nesac\n\n# Turn on debugging:\nset -x\n\n# Turn off debugging:\nset +x\n\n# Retrieve N-th piped command exit status\nprintf 'foo' | fgrep 'foo' | sed 's/foo/bar/'\necho ${PIPESTATUS[0]}  # replace 0 with N\n\n# Lock file:\n( set -o noclobber; echo > my.lock ) || echo 'Failed to create lock file'\n\n# Fork bomb\n:(){ :|:& };:\n\n# Unix Roulette\n# (Courtesy of Bigown's answer in the joke thread)\n# DANGER! Don't execute!\n[ $[ $RANDOM % 6 ] == 0 ] && rm -rf /* || echo Click #Roulette\n\n# for loop in one line\nfor i in $(seq 1 4); do echo $i; done\n\n# Test if a program exists in the path\n# There are false positives: aliases and functions\ncommand -v ${program} >/dev/null 2>&1 || error \"${program} not installed\"\n\n# Redirection\n# Please note that 2>&1 goes after\nmy_command > command-stdout-stderr.txt 2>&1\nmy_command > /dev/null 2>&1\n# Redirect stdout and stderr of cmd1 to cmd2\ncmd1 |& cmd2\n\n# Convert spaces to underscores in filenames\nfor name in *\\ *; do mv -vn \"$name\" \"${name// /_}\"; done\n", "topic_type": "cheat.sheets", "format": "code"}

Follow @igor_chubin cheat.sh cheat.sheets