QUESTION 1 From my home directory, copy the file called cards to your home direc
ID: 3915036 • Letter: Q
Question
QUESTION 1 From my home directory, copy the file called cards to your home directory. Copy the following script to a file in your home directory. This will be your first shell script. You can name the file any name that you would like. Once the file exists, execute the script. #!/usr/bin/ksh grep -i 'Mantle' cards if [ $? ] then echo "The name Mantle was found" fi The above script will locate the string "Mantle" within the file called cards and output the lines and a success statement. True False 10 points QUESTION 2 Copy the following script to a file in your home directory. You can name the file any name that you would like. #!/usr/bin/ksh if [ -f /etc/passwd ] then echo "The file exists" else echo "The file does not exist" fi Execute the file (script) The script will locate the /etc/passwd file and tell you that it exists True False 10 points QUESTION 3 Copy the file called list from my home directory. Copy the following script to a file in your home directory. You can name the file any name you would like. #!/usr/bin/ksh for index in `cat list` do echo $index done Execute the file (script). The script will output each line contained in the file called list. True False 10 points Click Save and Submit to save and submit. Click Save All Answers to save all answers.
Explanation / Answer
1) #!/usr/bin/ksh
grep -i ‘Mantle’ cards
if [ $? ]; then
echo “The name Mantle was found”
fi
Ans) False; The script will always print “The name Mantle was found” because whenever you will run grep the return code is not checked in the if condition. For that reason, this script is not correct. If [ $? = 0 ] is used in the ‘if’ condition, then the script will work perfectly.
2) #!/usr/bin/ksh
if [ -f /etc/passwd ]; then
echo "The file exists"
else
echo “The file does not exist”
fi
Ans) True; In this script the if condition is using a ‘-f’ which that will check for the file whether it exists or not. So, it will check that file and it will print “the file exists”. This script will work fine.
3) #!/usr/bin/ksh
for index in `cat list` do
echo $index
done
Ans) False; The script will print each line of the ‘list’ file, but it will not print line-wise. One word will be printed in one line. Each line only print one word.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.