What's wrong with the do statement?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What's wrong with the do statement?
# 1  
Old 08-28-2012
What's wrong with the do statement?

hi guys,

here's the code

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

Code:
$ 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

Code:
$ sh getsums.sh

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

Code:
$ 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
# 2  
Old 08-28-2012
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.
This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 08-28-2012
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.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 08-28-2012
$ cat getsums.sh |head -39
#!/usr/bin/sh
.
.
.
for FILE in ${FILENAME}
do >> line 39
gzip -t ${FILE} 2>/dev/null
# 5  
Old 08-28-2012
Run script with options -vx set and post the output (probably best as an attachment).
This User Gave Thanks to RudiC For This Post:
# 6  
Old 08-28-2012
im sorry if i dont understand your suggestion correctly.. is it like this?

Code:
$ 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 ----------

Quote:
Originally Posted by elixir_sinari
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.
i FTP the file, i think it's binary mode.
# 7  
Old 08-28-2012
Add a line set -vx to the biginning of the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Whats wrong with this If statement?

Hi I am pretty new to bash scripting.I am trying to write the if statement in bash and it give me error. Can you please help me what I am doing wrong in If statement? if && && then fector=$kk; divide=$DB_SIZE/$kk; echo "factor value:$fector" echo"divide value:$divide"... (4 Replies)
Discussion started by: Gevni
4 Replies

2. UNIX for Beginners Questions & Answers

Whats wrong with this If statement?

Hi I am pretty new to bash scripting.I am trying to write the if statement in bash and it give me error. Can you please help me what I am doing wrong in If statement? if && && then fector=$kk; divide=$DB_SIZE/$kk; echo "factor value:$fector" echo"divide value:$divide"... (1 Reply)
Discussion started by: Gevni
1 Replies

3. Programming

Whats wrong with this If statement?

Hi I am pretty new to bash scripting.I am trying to write the if statement in bash and it give me error. Can you please help me what I am doing wrong in If statement? Code: if && && then fector=$kk; divide=$DB_SIZE/$kk; echo "factor value:$fector" echo"divide... (1 Reply)
Discussion started by: Gevni
1 Replies

4. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

5. Shell Programming and Scripting

What is wrong with this awk statement?

echo $line | awk -F, "BEGIN {if(NF==10) && /'"${MONTH}"' '"${DAY}"' '"${TIMEH}:"'/,0 {print $10"-"$4} else {print $13"-"$4}}" if the fields in the line is equal to 10, print the values of this specified fields "$10 and $4". if the fields in the line is anything but 10, print the values of... (5 Replies)
Discussion started by: SkySmart
5 Replies

6. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

7. Shell Programming and Scripting

Something is wrong with this switch( case statement.

I started writing a script to save the files from a camera I got the other day, which mounts in /Volumes , and I got into it and started building this menu. The only problem is that the switch case is coming up as a syntax error at the parenthesis after a case. Here is the code: while : do ... (2 Replies)
Discussion started by: snakemasterAK
2 Replies

8. Shell Programming and Scripting

whats wrong with this find statement ?

cmd="find /a/technologies -name '*.jar' | grep \"Tuning/specificloader/lib\"" echo $cmd for index in `$cmd` do SL_JARS="${SL_JARS}:${index}" done gives error ==> find: paths must precede expression Usage: find but for index in... (2 Replies)
Discussion started by: crackthehit007
2 Replies

9. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

10. Shell Programming and Scripting

What's wrong with this simple statement?

I know that this is a ridiculously simple statement, but I am getting an error when I execute it, and I can't figure out what it is. Can anyone point me in the right direction? #!/bin/ksh integer dateMonth=0 integer intZero=0 if then dateMonth = 1 fi echo $dateMonth (7 Replies)
Discussion started by: mharley
7 Replies
Login or Register to Ask a Question