LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Shell Script problem (https://www.linuxquestions.org/questions/linux-software-2/shell-script-problem-670237/)

Abstractt 09-16-2008 05:43 AM

Shell Script problem
 
Hi Everyone,

I got a little shell problem. When I execute the following shell script:

for((i=0; i<=2; i++))
do
/usr/bin/wget -t 1 -O/dev/null -q http://ur;
echo "passed";
sleep 5;
done


I'm getting this error:

'ownloadCron.sh: line 1: syntax error near unexpected token `
'ownloadCron.sh: line 1: `for((i=0; i<=2; i++))

But I can't find any unexpected token exactly. What can be the problem?

Thanks Arian

theYinYeti 09-16-2008 06:00 AM

then you must have typed a “`” character, which shouldn't be there.

Yves.

Abstractt 09-16-2008 06:14 AM

Fixed
 
I checked but I couldn't find any. So I typed everything again, but now not in an editor of windows but in the vi editor on the commandline. It worked. Could it have to do something with how the files are stored in windows?

snkmchnb 09-16-2008 07:46 AM

Quote:

Originally Posted by Abstractt (Post 3281850)
I checked but I couldn't find any. So I typed everything again, but now not in an editor of windows but in the vi editor on the commandline. It worked. Could it have to do something with how the files are stored in windows?

I had this issue yesterday, actually. Its the actual format the file is stored in.. at least that was my issue. Something you can do is use and editor like Notepad++ (if you have to write it in Windows) which allows UNIX file formats.

colucix 09-16-2008 04:00 PM

The main concern is the sequence of characters used by windows to terminate a line. DOS and Windows adopted the CR+LF style, that is a carriage return followed by a line feed. In Unix notation it is the sequence \r\n.

Unix systems adopted a simple LF, that is \n. Commonly you call this a newline character. For text files created in Windows you can use the utility dos2unix to convert them in Unix format. See man dos2unix for details.

The presence of a carriage return triggers some common errors in BASH and other shell scripting languages. To discover the presence of \r\n in Unix or Linux you can try the od command. Suppose you have a file containing the line "Hello world!". If it has been created in Linux you will see:
Code:

$ od -c file
0000000  H  e  l  l  o      w  o  r  l  d  !  \n
0000015

whereas if it has been created in Windows you will see:
Code:

$ od -c file
0000000  H  e  l  l  o      w  o  r  l  d  !  \r  \n
0000016

See also http://en.wikipedia.org/wiki/Newline for details about the "newline problem".


All times are GMT -5. The time now is 07:14 AM.