if
if (( $# < 3 ))
then
printf "%b" "Error. Not enough arguments.\n"
printf "%b" "usage: myscript file1 op file2\n"
exit 1
elif (( $# > 3 ))
also...
if list; then list; [ elif list; then list; ] ... [ else list; ] fi
or
#!/bin/sh
DIRPLACE=/tmp
INFILE=/home/yucca/amazing.data
OUTFILE=/home/yucca/more.results
if [ -d "$DIRPLACE" ]
then
cd $DIRPLACE
if [ -e "$INFILE" ]
then
if [ -w "$OUTFILE" ]
then
doscience < "$INFILE" >> "$OUTFILE"
else
echo "cannot write to $OUTFILE"
fi
else
echo "cannot read from $INFILE"
fi
else
echo "cannot cd into $DIRPLACE"
fi
-lt : less than -le : less / equal to -gt : greaterthan -ge : greater / equal to -eq : equal -ne : not equal
if [[ "${MYFILENAME}" == *.jpg ]]
shopt -s extglob
if [[ "$FN" == *.@(jpg|jpeg) ]]
shopt -s : turn on shell options extglob: we can now do extended pattern matching aka patterns seperated by '|' andd grouped by ( )
@(...) : just once *(...) : zero or more +(...) : one or more ?(...) : zero or one !(...) : not this but anything else
-b : is a block special device (i..e /dev/sda1) -c : is like /dev/tty -d : is dirr -e : exists -f : is a fle -g : has group ID set -G : owned by user's group -h : is symbolic link -k : sticky bit -N : modified since it was rread -O : owned by user -p : named pipe -r : readable -s : has a size > 0 -S : socket -w : writable -x : executable
WHILE + MATH
while (( COUNT < MAX ))
do
some stuff
let COUNT++
done
while [ -z "$LOCKFILE" ]
do
some things
done
while read lineoftext
do
process $lineoftext
done
svn status mysrc |
while read TAG FN
do
if [[ $TAG == \? ]]
then
echo $FN
rm -rf "$FN"
fi
done
dashes : print out X number of any character
dashes :: prints 72 dashes
dashes 50 :: just 50
dashes -c = 50 :: 50 '='s
dashes -c x :: 72 x's