You are on page 1of 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 $Usage
exit 1
fi
FILE=$1
if [ ! -f $FILE]; then
echo "'$FILE' not found "
exit 1
else
sed -i '/^[ \t]*\/\*/d;' $FILE
echo "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 properly
Usage="Usage: $name [-h] [-s N] [directory]"
# if the command is executed without any arguments
if [ $# -eq 0 ]; then
# then it should display the usage
echo $Usage
# then it exits from the execution shell
exit 1
# end of if branch
fi
# base case or the fail condition for the loop
# this loops until the aregumets passed are equal to zero

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}

${infile} > ${outfile}

You might also like