Sum in shell script

Posted by Dinis Monteiro on Stack Overflow See other posts from Stack Overflow or by Dinis Monteiro
Published on 2011-01-06T05:13:50Z Indexed on 2011/01/06 5:53 UTC
Read the original article Hit count: 225

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about linux

Related posts about shell