Upload
alwaysastudent
View
213
Download
0
Embed Size (px)
Citation preview
8/16/2019 2016 Answers Assignment2 Question2 Question3 Question4 Software Development Tools Csc2408 USQ
1/3
\documentclass[11pt]{article}
\title{Software Development Tools - Assignment 2}\author{alwaysastudent}
\begin{document}
\maketitle
\begin{Large}·Answer 2\end{Large}
\begin{verbatim}#!/bin/bash
NAME=${0##*/}Usage="Usage: {script name} {target file}"if [ $# -ne 2]; then
echo $Usageexit 1
fi
FILE=$1
if [ ! -f $FILE]; thenecho "'$FILE' not found "exit 1
elsesed -i '/^[ \t]*\/\*/d;' $FILEecho "Removed Commented lines"
fi
\end{verbatim}\begin{Large}
Answer 3
\end{Large}\begin{verbatim}#!/bin/bash#A script demonstrating an until-loop and command line processing## List the regular files of a directory greater than a given size# the name of the shell script is the name of the file.name=${0##*/}# this will display how the command has to be used# what are the arguments that it takes to execute properlyUsage="Usage: $name [-h] [-s N] [directory]"
# if the command is executed without any argumentsif [ $# -eq 0 ]; then# then it should display the usageecho $Usage# then it exits from the execution shellexit 1# end of if branchfi# base case or the fail condition for the loop# this loops until the aregumets passed are equal to zero
8/16/2019 2016 Answers Assignment2 Question2 Question3 Question4 Software Development Tools Csc2408 USQ
2/3
until [ $# -eq 0 ]# beginning of the loop instrutions.do# switch case take the first argument passescase $1 in
# if the first argument is -s then shift and-s) shift# then assigne the next argume to a variable called sizesize=$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 shellexit 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 caseesac
# end of do loopdone
# assign the printed present working directory to the directory variabledirectory=${directory:-`pwd`}# begining of if statement#if the present working directory is not a diretory thenif [ ! -d $directory ]; then# then print that the pwd is not a directory and exit the shellecho "`$directory' is not a directory"exit 1# end of if statementfi
#initializing a variable arg as NULL.arg=''# beginning of if statement# if the size variable is not empty/ not NULL thenif [ $size != '' ]; then# making a string by appending -size $value_size and storing it in variable argarg="-size +$size"# end of if statementfi# 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 given)# -type f will find the files
# -exec will fork the ls -l commandfind $directory $arg -type f -exec ls -l {} ';'\end{verbatim}
\begin{Large}
Answer 4
\end{Large}
8/16/2019 2016 Answers Assignment2 Question2 Question3 Question4 Software Development Tools Csc2408 USQ
3/3
\begin{verbatim}
#!/bin/bash
Usage="Usage: $0 filename"name=${0##*/}
if [$# -ne 1]; thenecho "$Usage"exit 1fi
if [ -z "$1" ] || [ ! -e "$1" ]; then echo "$1: File does not exist." exit 1fi
infile=$1outfile=$1.out
grep -E
^[[:space:]]*[^[:space:]]+[[:space:]]*$
${infile} > ${outfile}
exit 0\end{verbatim}
\end{document}