Professional Documents
Culture Documents
2016 Answers Assignment2 Question2 Question3 Question4 Software Development Tools Csc2408 USQ
2016 Answers Assignment2 Question2 Question3 Question4 Software Development Tools Csc2408 USQ
2016 Answers Assignment2 Question2 Question3 Question4 Software Development Tools Csc2408 USQ
until [ $# -eq 0 ]
# beginning of the loop instrutions.
do
# switch case take the first argument passes
case $1 in
# if the first argument is -s then shift and
-s) shift
# then assigne the next argume to a variable called size
size=$1
# shift again to accept next argument and ends because of ;
shift;;
# if the switch case take -h as the first argument
# then print the usage information.
-h) echo $Usage
# then exit the shell
exit 0;;
# if there is a * passed as a first argument then
# first aregument will be assigned to the directory variable
*) directory=$1
# shift to look for the next argument and ends because of ;
shift;;
# end of switch case
esac
# end of do loop
done
# assign the printed present working directory to the directory variable
directory=${directory:-pwd}
# begining of if statement
#if the present working directory is not a diretory then
if [ ! -d $directory ]; then
# then print that the pwd is not a directory and exit the shell
echo "$directory is not a directory"
exit 1
# end of if statement
fi
#initializing a variable arg as NULL.
arg=
# beginning of if statement
# if the size variable is not empty/ not NULL then
if [ $size != ]; then
# making a string by appending -size $value_size and storing it in variable arg
arg="-size +$size"
# end of if statement
fi
# by using the find command we will filter or search the pwd with the
# arg which will be containing -size 100 ( for example if 100 is size value give
n)
# -type f will find the files
# -exec will fork the ls -l command
find $directory $arg -type f -exec ls -l {} ;
\end{verbatim}
\begin{Large}
Answer 4
\end{Large}
\begin{verbatim}
#!/bin/bash
Usage="Usage: $0 filename"
name=${0##*/}
if [$# -ne 1]; then
echo "$Usage"
exit 1
fi
if [ -z "$1" ] || [ ! -e "$1" ]; then
echo "$1: File does not exist."
exit 1
fi
infile=$1
outfile=$1.out
grep -E ^[[:space:]]*[^[:space:]]+[[:space:]]*$
exit 0
\end{verbatim}
\end{document}