2
\documentclass[11pt]{article} \title{SWDT-Assignment 2 Ans 1A} \author{alwaysastudent} \date{October 2015} \begin{document} \maketitle \begin{verbatim} Answer 2 #!/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} \newpage \begin{verbatim} Answer 3 #!/bin/bash if [ $# -ne 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: $0 [ -h | --help ]" >&2 echo " $0 FILE1 FILE2" >&2 exit 1 fi if [ -z "$1" ] || [ ! -e "$1" ]; then echo "$1: File does not exist." exit 1 fi if [ -z "$2" ] || [ ! -e "$2" ]; then echo "$2: File does not exist." exit 1 fi if [ "$1" -ef "$2" ]; then

Answers Software Development Tools 2015 Assignment 2

Embed Size (px)

DESCRIPTION

This has the answers to all the question of assignment 2 of software development tools

Citation preview

Page 1: Answers Software Development Tools 2015 Assignment 2

�\documentclass[11pt]{article}

\title{SWDT-Assignment 2 Ans 1A}\author{alwaysastudent}\date{October 2015}

\begin{document}

\maketitle

\begin{verbatim}

Answer 2

#!/bin/bash

NAME=${0##*/}Usage="Usage: {script name} {target file}"if [ $# -ne 2]; then

echo $Usageexit 1

fi

FILE=$1

if [ ! -f $FILE]; then echo "'$FILE' not found "exit 1

elsesed -i '/^[ \t]*\/\*/d;' $FILEecho "Removed Commented lines"

fi

\end{verbatim}

\newpage

\begin{verbatim}

Answer 3

#!/bin/bash

if [ $# -ne 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: $0 [ -h | --help ]" >&2 echo " $0 FILE1 FILE2" >&2 exit 1fi

if [ -z "$1" ] || [ ! -e "$1" ]; then echo "$1: File does not exist." exit 1fiif [ -z "$2" ] || [ ! -e "$2" ]; then echo "$2: File does not exist." exit 1fi

if [ "$1" -ef "$2" ]; then

Page 2: Answers Software Development Tools 2015 Assignment 2

echo "$1 and $2 are the same file." exit 0fi

p1=`ls -l $1 | cut -c 2-10`p2=`ls -l $2 | cut -c 2-10`

echo "DEBUG: permission1: $p1, permissions2: '$p2'"

if [ $p1 = $p2 ]; then echo "permissions are same:" echo "$p1"

exit 0else

echo "permissions are not same:" echo "$1 has permission $p1" echo "$2 has permission $p2"

exit 1fi\end{verbatim}

\begin{verbatim}

Answer 4

#!/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}\\