Using the fact that the shell construct ${#var} gives the number of characters stored in var, rewrite wc in the shell. Be sure to use integer arithmetic! (Notes: Change your IFS variable to just a newline character so that leading whitespace characters on input are preserved, and also use the -r option to the shell's read command so that terminating backslash characters on the input are ignored.)

What will be an ideal response?


# duplicate wc as a shell script

origIFS=$IFS

for filename in $@
do
lines=0

var=$(cat $filename)
chars=${#var}

set $(cat $filename)
words=$#

" IFS="
while read line
do
lines=$(( $lines + 1 ))
done < $filename

echo $filename - chars=$chars, words=$words and lines=$lines
IFS=$origIFS
done

Computer Science & Information Technology

You might also like to view...

Critical Thinking QuestionsCase D-2Beth is running for student council, and she is in the middle of creating her campaign poster. She is using Photoshop because of the various ways it allows her to add effects to type. Beth wants to fill her type with something eye-catching. Which of the following options does she have?

A. drop shadow and gradient B. gradient and imagery C. emboss and drop shadow D. color and glow

Computer Science & Information Technology

How might redundancy of programs and data be useful in the construction of highly reliable systems?

What will be an ideal response?

Computer Science & Information Technology

A thesaurus provides:

A) Words with similar meanings B) Reading level of the document C) Correct word usage

Computer Science & Information Technology

A(n) ________ data table changes one value in a formula using input from either a row or a column

A) one-variable B) zero-variable C) two-variable D) variable

Computer Science & Information Technology