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...

When customizing the Windows 10 Start menu, the easiest way to add an app is to ________

A) right-click the app and access the shortcut menu B) turn the Live Tile off C) double-click an app that is located on the taskbar D) drag an app that is located on the taskbar to the Start menu

Computer Science & Information Technology

The ________ performs all of a PC's arithmetic and logic operations

Fill in the blank(s) with correct word

Computer Science & Information Technology