BASH & KSH tips & tricks

Handle variables

indirection expansion

var=EDITOR

echo ${!var}

Handle conditions

continue / break / return

break a while or case loop

break

skip to the next iteration of for, while, until or select loop

continue

exit a function and not the whole script

return

commands within an error

false || { echo first command; echo second command; }

Text processing

for vs. while read

https://stackoverflow.com/questions/14040911/reading-a-file-line-by-line-in-ksh

https://www.cyberciti.biz/faq/ksh-read-file/

Other tips & tricks

unix2date

GNU

date -d @timestamp

BSD/OSX

date -r timestamp

press any key…

https://stackoverflow.com/questions/43030991/korn-shell-how-can-i-make-press-any-key-to-continue

echo

print tabs and new lines

echo -e foo\\tbar\\nnewline

write to standard error

echo 'There were errors' >&2

float

https://unix.stackexchange.com/questions/369788/how-to-compare-two-float-values-in-ksh

https://stackoverflow.com/questions/11481648/arithmetic-syntax-error-in-shell-script

https://askubuntu.com/questions/1309320/ksh-syntax-error-invalid-arithmetic-operator-error-token-is-111111111-2-555

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=894802


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5
Copyright © 2022 Pierre-Philipp Braun