# write trace to stderr for every commandset -xv## Error Handlingset -o errexit;set -o pipefail;set -o nounset;
POSIX: Add values to input Arguments with set
#!/bin/shset -- one twoecho $1echo $2# also useful when loopingfor arg; do echo $argdone
Shell Loopings
# endlesswhile :; do echo "endless loop"done# for loop with counterfor (( i=1 ; i<=5 ; i++ )); do echo "Hello World"done# until loopuntil obs-cli OpenProjector >/dev/null 2>&1; do log "waiting for obs to get ready ..." sleep 1done;# Columnized printingfor d in ./*; do printf "$(basename "$d")" printf " " echo " asdfasdf asd as df"done | column -t# iterator over results from find with while loop# loops over found git repositoriesfind -L ~/repos -name .git -type d -prune -exec dirname {} \; | while read -r line; do echo line: $line done
Printing Color Codes
# print red textecho -e "\e[31mRed Text\e[0m"# or use tput_RED=$(tput setaf 1)_BLUE=$(tput setaf 4)_GREEN=$(tput setaf 2)_GOLD=$(tput setaf 3)_BOLD=$(tput bold)_RESET=$(tput sgr0)