Tuesday, November 13, 2012

Cheat sheet on how to write shell scripts

at the to, put:

generate timestamp: `date +"%Y%m%d_%H%M"`

to append each command output to a log file AND send to console :
command | tee -a mylog.log

checking result of last command (it's the $? ):
if [ $? -ne 0 ]
echo OK
echo KO

to assign positional parameters:
set -- BLA
the result is that $1=BLA

No comments: