Problem with the Script....

Please advice I am having problem with the script below. The issue is the red below in the code.

#!/usr/bin/ksh
 
#Program Name and Directory Name
PROG=`basename $0`
PROG_DIR=`dirname $0`
 
cd /home/test1   � There are two files in this directory BUILD1.dat and BUILD2.dat  with 200 and 6 records respectively.
 
if [ -f *.dat ] ; then
 echo "Input File found...."  
 
 inp_file=`ls -1 *.dat`
 echo "File Name: " $inp_file    
 
 line_cnt=`wc -l $inp_file | cut -c1-8`
 echo "The line count is: $line_cnt"   �  This returns three values 200  and 6 and 206.
 
diff= `expr 301 - $line_cnt`
echo "The change is: $diff"    � This is my issue. I am not getting any values to this....
 
actual_diff=`expr $line_cnt - 1`  
echo "The actual count is: $actual_diff"      � This is my issue. I am not getting any values to this....
else
 echo "File Not found"
fi

The 'expr' command expects one numerical argument, not a collection :wink:

[house@leonov] wc -l in.file
9 in.file
[house@leonov] lines=$( wc -l in.file | cut -d ' '  -f 1 ); diff=$( expr $lines - 1 ); echo "$diff"
8

Thanks a bunch for the quick reply. I have one question. Incase of multiple or collection of files. How should we handle this situation.

Will appreciate any advice.

Thanks again

you have an extra space, in: diff= `expr 301 - $line_cnt`
this should be: diff=`expr 301 - $line_cnt`

plus, arithmetic evaluation could be done using: diff=$((301 - line))