COMP2004
Programming Practice
2002 Summer School


Kevin Pulo
School of Information Technologies
University of Sydney


(page 1)


More Unix Tools




(page 2)


Revision Control




(page 3)


Simple revisioning





(page 4)


PRCS




(page 5)


The shell




(page 6)


Simple commands I



overwriting)



(page 7)


Simple commands: echo


bash$ echo "Hello World" Hello World
bash$



(page 8)


Simple commands: cat


bash$ cat hello.txt Hello World
bash$


(page 9)


Redirection






(page 10)


Redirection caveat




(page 11)


Redirection caveat


prog file.txt > file.tmp
mv -f file.tmp file.txt

























(page 12)


Exit Status




(page 13)


If in shell


if cmp test.out outfile; then
echo "test passed"
else
echo "test failed"
fi


(page 14)


elif


if cmp test.out outfile; then
echo "test passed"
elif diff -i test.out outfile; then
echo "test passed (only just)"
else
echo "test failed"
fi


(page 15)


Exit in shell


if another_script; then
...
fi


(page 16)


Testing variables

























(page 17)


Putting stdout into variables


echo "f1.h f2.h f3.h" > file.lst
filelist=`cat file.lst`
cat $filelist
cat `cat file.lst`
cat $(cat file.lst)


(page 18)


Shell arithmetic


bash$ expr 3 + 8 \* 2 19
bash$


(page 19)


while


count=1
while [ $count -le 10 ]; do
echo "$count"
count=$(($count + 1))
done


(page 20)


while


while :; do
if [ -e "file.txt" ]; then
break
fi
sleep 1
done


(page 21)


Command line parameters




(page 22)


Example parameters


#!/gnu/usr/bin/bash
while [ $# -ge 1 ]; do
echo "$1"
shift
done


bash$ sample a bc defgh a
bc
defgh


(page 23)


case


case "$1" in
-d*)
cmd="diff"
;;
-c*)
cmd="cmp"
;;
*)
exit 1
;;
esac
$cmd file1.txt file2.txt


(page 24)


case




(page 25)


Testing script



#!/gnu/usr/bin/bash
prog < test.in > outfile
if cmp test.out outfile; then
echo "test passed"
else
echo "test failed"
fi


(page 26)


Pipes


if prog < test.in | cmp - test.out; then
echo "test passed"
else
echo "test failed"
fi


(page 27)


Multiple Tests




(page 28)


Running Multiple Tests


#!/gnu/usr/bin/bash
for infile in tests/*.in; do
name=`basename $infile .in`
if prog < $infile | cmp - \
tests/$name.out; then
echo "$name : passed"
else
echo "$name : failed"
fi
done
















(page 29)


sed




(page 30)


awk


awk -F: '/summer semester/ {print $1}' \
/etc/passwd



(page 31)


Other useful utilities








(page 32)