Bash Cheatsheet

Conditional from function is_field() { local field for field in $FIELDS; do if [[ "$field" == "$1" ]]; then return 0 fi done return 1 } if is_field; then ... fi List TRAILERS=() TRAILERS+=( "--trailer" "Co-authored-by: $(get_author_name) <$(get_author_email)>") git commit "$@" "${TRAILERS[@]}" Loop over multiline variable LINES=$(cat <<EOF line1 line2 EOF ) while IFS='\n' read line; do ... done <<< "$LINES"

December 5, 2025  |  🏷️Bash

Test color support in bash

for i in {0..255} ; do printf "\x1b[48;5;%sm%3d\e[0m " "$i" "$i" if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then printf "\n"; fi done

November 18, 2017  |  🏷️Bash