What's wrong with the do statement?

hi guys,

here's the code

$ cat getsums.sh
#!/usr/bin/sh
FILENAME=$1
DELIMITER=$2
FIRST_COL=$3
SECOND_COL=$4
SALESDATE_COL=$5
STOREID=$6
UPC=$7
GTIN=$8
PROMOID=$9
echo ""
echo ".:Summation Tool:."

for FILE in ${FILENAME}
do
        gzip -t ${FILE} 2>/dev/null

        if [ $? -eq 1 ];
        then
                comm=cat
        else
                comm=gzcat
        fi
.
.
.
done

everytime i execute it, it keeps saying that the error is in "do"...

$ sh getsums.sh ft-GNCT-3398-CD-2012-07-07-140112.txt.gz

.:Summation Tool:.
getsums.sh[36]: ^M:  not found.
' is not expected.ntax error at line 39 : `do
$ sh getsums.sh

.:Summation Tool:.
getsums.sh[36]: ^M:  not found.
' is not expected.ntax error at line 39 : `do
$ sh getsums.sh ft-GNCT-3398-CD-2012-07-07-140112.txt.gz "      " 22 23 1 2 4

.:Summation Tool:.
getsums.sh[36]: ^M:  not found.
' is not expected.ntax error at line 39 : `do

can someone please explain me what is this error?

I think i was able to execute this script before, but somehow now.. it keeps having error like this. for your advise please. thanks guys

Seems carriage-return characters are in your file. How did you get this file? From a Windows machine? FTP? binary mode?
Use dos2unix utility on the file.

1 Like

1) You don't list the line in question (36 or 39).
2) Looks like there is a <carriage return> (^M or \r or 0x0D) char in one of your parameters, probably $1.

1 Like

$ cat getsums.sh |head -39
#!/usr/bin/sh
.
.
.
for FILE in ${FILENAME}
do >> line 39
gzip -t ${FILE} 2>/dev/null

Run script with options -vx set and post the output (probably best as an attachment).

1 Like

im sorry if i dont understand your suggestion correctly.. is it like this?

$ sh getsums.sh -vx ft-GNCT-3398-CD-2012-07-07-140112.txt.gz "  " 22 23 1 2 4

.:Summation Tool:.
getsums.sh[36]: ^M:  not found.
' is not expected.ntax error at line 39 : `do

---------- Post updated at 05:34 AM ---------- Previous update was at 05:32 AM ----------

i FTP the file, i think it's binary mode.

Add a line set -vx to the biginning of the script.

hi guys, thanks a lot for your replies,

it seems that the problem is the FTP transfer mode i used,

before i used binary mode, which resulted to this error..

i changed the Transfer type to "Auto"

and it resulted as expected

$ sh qa_del_2.sh ft-GNCT-3398-CD-2012-07-07-140112.txt.gz "     " 22,23,1,2,4
sales_date|cust_id|UPC|sum(POS_QTY)|sum(POS_AMT)|<source_file>
2012-07-05|PL_000000000034014|PL_2003007476012|75|   75.9200|ft-GNCT-3398-CD-2012-07-07-140112.txt.gz
2012-07-03|PL_000000000034012|PL_2003000322606|19|   19.5000|ft-GNCT-3398-CD-2012-07-07-140112.txt.gz
2012-07-01|PL_000000000034010|PL_2003005081201|38|   38.9800|ft-GNCT-3398-CD-2012-07-07-140112.txt.gz
2012-07-02|PL_000000000034011|PL_2003010201151|39|   39.7700|ft-GNCT-3398-CD-2012-07-07-140112.txt.gz
2012-07-02|PL_000000000034011|PL_2003000322491|78|   78.0000|ft-GNCT-3398-CD-2012-07-07-140112.txt.gz

thanks to you guys for helping me figure this out! :slight_smile: