Shell boot camp: v0.1 totierne
-------------------------
guide howto examples
Using /bin/sh /bin/ksh or /bin/bash, see man for more details,
use on unix/linux or windows using cygwin
Loops:
for f in `ls`
do
echo $f
done
ls | while read line
do
echo $line
done
Test:
if test "m$1" = "m"
then
echo 'first arg blank, also -eq [equals] -ne [does not equal] (for numbers)
= != for strings'
fi
$* all args
$# number of args
$? 0 if last command succeeds
$$ current process id useful for creating per execution files
# comment
set -x #set debug on
sed:
echo from | sed 's/from/to/g' #becomes to
regular expressions can be used in sed, special characters need to be backslashed:
^ start of line
$ end of line
. any char
+ 1 or more chars
* 0 or more chars
s/zz\(expression\)zz/\1/g removes zz and keeps expression
[^ \t] anything but space or tab
[a-z,A-Z] any character (this could be a mistake, deliberate one for the
audience]
export INCREMENT=`expr $INCREMENT + 1` #increment by 1
` execute quote
' quote literally
" quote literally but expand $INCREMENT to value
/dev/null takes in input
> /dev/null 2>&1 #put standard out and standard error into /dev/null
i.e. junk them