Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UNIX / C: modify Code: Modify the mySpell script so that if you fail to enter th

ID: 3711075 • Letter: U

Question

UNIX / C: modify Code:

Modify the mySpell script so that if you fail to enter the file name, it will print a reminder, e.g., “Usage: mySpell filename”.

HERE is the Code:

% more mySpell
#!/bin/sh
# An improved spelling checker
file=$1
for word in ‘spell $file‘
do
# grep tries to find the line where $word occurs in $file
line=‘grep -n $word $file‘
#print out a line
echo " "
#print out the following line
echo "Missplled word: $word"
#print out the line where the misspelled word occurs
echo "$line"
done

2.) Modify the delFile script so that it will test if the one to be deleted is a directory, in this case, it should call rmdir instead of rm to delete it. Notice that the following line tests if dirname is a directory, which sends back True if the value of $dirname holds a directory’s name. if test ! -d $dirname

Here code:

% more delFile
#!/bin/sh
#Delete a file interactively
filename=$1
if test ! -f $filename
then
echo "There is no file "$filename"."
else
echo "Do you want to delete "$filename"?"
read choice
if test $choice = y
then
rm $filename
echo "$filename" deleted
else
echo "$filename" not deleted.
fi
fi

Explanation / Answer

Part 1:

Add after #!/bin/bash

If [$# -ne 1]

then

echo "usage: myspell <filename>";

break;

fi

In part 2

Modify after choice statement below

read choice

if test $choice=y

then

If test -d $filename

then

rmdir $filename

else

rm $filename

fi

echo "$filename" deleted

else

echo "$filename" not deleted

fi