Showing posts with label Unix shell. Show all posts
Showing posts with label Unix shell. Show all posts

Tuesday, November 13, 2012

Cheat sheet on how to write shell scripts

at the to, put:
#!/bin/bash


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 ]
then
echo OK
else
echo KO
fi


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