S12 - OS - Lab 4
S12 - OS - Lab 4
FPT UNIVERSITY
Lab 4 for Operating Systems
Learning outcome
Upon successful completion of this lab, you will be able
How to program the shell script into Fedora
Programming in Shell
String operator
o =, !=
o Unary: -z (string have zero length), -n (string have size)
Logic operator: !, -a, -o
Select construct
o Syntax
case <var> in
value1)
command1
;;
valueN)
commandN
;;
*)
command
;;
esac
o Ex
#!/bin/sh
ftype=`file "$1"`
case "$ftype" in
"$1: Zip archive"*)
unzip "$1" ;;
"$1: gzip compressed"*)
gunzip "$1" ;;
"$1: bzip2 compressed"*)
bunzip2 "$1" ;;
*) error "File $1 can not be uncompressed with smartzip";;
esac
For loop
o Syntax
for variable in const1 const2 …
do
commands
done
o Ex:
#!/bin/sh
if [ $# -eq 0 ]
then
echo “Thieu tham so“