Maxline.sh Script Logic #!/bin/ XXX ########## # Script name: maxlines.sh # Case
ID: 3885670 • Letter: M
Question
Maxline.sh Script Logic
#!/bin/XXX
##########
# Script name: maxlines.sh
# Case #1: ./maxlines.sh
# Case #2: ./maxlines.sh /bin
# Case #3: ./maxlines.sh .
# Lab Assignment: 2-1
# Functionality: This script reads each file in a directory and counts the
# number of new lines. After determining this count, the file name and new
# line count are saved. The new line count is then compared to each
# file to determine the file with the highest new line count.
# Output an error message because more than one argument is present on the
# command line.
ERROR1="error: can only use 0 or 1 arguments. usage: maxlines.sh [directory]"
ERROR2="error: argument must be a directory. usage: maxlines.sh [directory] "
# Verify that more than one command line argument doesn't exist.
if [[ $# -gt 1 ]]
XXXX
printf "$ERRORX"
exit 1
XX
DIR="."
# Case #2 and 3.
if [[ $# XXX 1 ]]
then
# Is the directory entry a directory?
if [[ -d XX ]]
then
# Assign Variable DIR to command line directory.
DIR="$1"
else
printf "$ERRORX"
exit 1
fi
fi
# All Cases are processed with the following code.
cd $DIR
FILE=$(wc -l `ls` 2>/dev/null | sort XXX | tail -n X | head -n X)
printf "File `echo $FILE | awk '{print $X}'` has the maximum lines with `echo $FILE | awk '{print $X}'` lines. "
exit 0
what do we put in the XXX ?
Explanation / Answer
ERROR1="error: can only use 0 or 1 arguments. usage: maxlines.sh [directory]"
ERROR2="error: argument must be a directory. usage: maxlines.sh [directory] "
# Verify that more than one command line argument doesn't exist.
if [[ $# -gt 1 ]]
then
printf "$ERRORX"
exit 1
fi
DIR="."
# Case #2 and 3.
# The number of arguments on the command line equals one.
if [[ $X -eq 1 ]]
then
# Is the directory entry a directory?
if [[ -X $1 ]]
then
# Assign the command line argument to the variable,
DIR="$X"
else
printf "$ERRORX"
exit 1
fi
fi
# All cases are processed with the following code.
# Change directory to the indicated variable content.
cd $XXX
# Assign file name with highest number of new lines to the variable FILE.
FILE=$(wc –X `ls` 2>/dev/XXXX | sort –X X | tail –X X | head –X X)
# Print statement for all cases.
printf "File `echo $FILE | awk '{print $X}'` has the maximum lines with `echo $XXXX| awk '{print $X}'` lines. "
exit 0