Sum in shell script
- by Dinis Monteiro
Why can't I create a sum of total words in this script? I get the result something like:
120+130
but it isn't 250 (as I expected)! Is there any reason?
#!/bin/bash
while [ -z "$count" ] ;
do
echo -e "request :: please enter file name "
echo -e "\n\tfile one : \c"
read count
itself=counter.sh
countWords=`wc -w $count |cut -d ' ' -f 1`
countLines=`wc -l $count |cut -d ' ' -f 1`
countWords_=`wc -w $itself |cut -d ' ' -f 1`
echo "Number of lines: " $countLines
echo "Number of words: " $countWords
echo "Number of words -script: " $countWords_
echo "Number of words -total " $countWords+$countWords_
done
if [ ! -e $count ] ; then
echo -e "error :: file one $count doesn't exist. can't proceed."
read empty
exit 1
fi