HELP!!!! Using Putty (UNIX) !!! Commands to study to answer this question: Read
ID: 3796718 • Letter: H
Question
HELP!!!! Using Putty (UNIX) !!!
Commands to study to answer this question: Read about test, shift, while loop, expr,
displaying the value of the two-character variable $1 using echo command
1) Exit from script, if is currently enabled; if it is not enabled, skip this item (1)
2) Using the vi editor, create a shell script file that displays the first 12 command line arguments. You must use a while loop, expr and shift shell commands in the script to do this question.
3) Issue script command to capture the output of the items below
4) Add execute permission to the file
5) Display the attributes of the script file
6) Display the content of the script file
7) Run the script file by typing the name of the script file and specifying 14 or more arguments
The following are helpful hints in creating the shell script file for this question:
The expr command can be used to perform arithmetic operations. For example, the value of a user defined variable, count can be incremented by 1 (that is, add 1 to count) by using the following expr command.
count=`expr $count + 1`
NOTE: (1) there should be no space before and after = when storing a value into a variable, (2) Reverse quote (`) is used and not forward quote (‘) in the above command.
Explanation / Answer
#!/bin/bash
exec 10<&0
exec < $1
in=$1
file="current_line.txt"
let count=0
while read LINE
do
((count++))
echo $LINE > $file
if [ $? -ne 0 ]
then echo "Error in writing to file ${file}; check its permissions!"
fi
done
$ chmod a+x name.sh
echo "Number of lines: $count"
echo "The last line of the file is: `cat ${file}`"
echo "Expected number of lines: `wc -l $in`"
exec 0<&10 10<&-
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.