script question

Anyone know why this won't work?

#!/usr/bin/ksh

for db in `cat /etc/oratab|egrep ':N|:Y' | grep -v \* | cut -f1 -d":"`

do
		  echo "************************"
    echo "database is $db"
    echo "************************"
done

I am getting an error on the line that starts with the "for" statement. The command in quotes works fine from the command prompt.

TIA

Based on what bash would do: Backticks '...' are equal to dollar sign-brackets $(...). You do use both nested which should result in the shell trying to to execute your db names rather than returning them.

You're right... I was testing that way. Ok, in the example above I edited them out, and it still won't work.

I'm getting this error message:

oratab_loop.ksh[2]: ^M: not found.
' is not expected.: 0403-057 Syntax error at line 5 : `

^M is the end-of-line mark of Windows. Seems this file does not have unix EOL (well, makes sense for plattform independence of Oracle's tools).

"^M: not found." sounds a bit like it tries to execute it. Does this error message change as you change from backticks and dollar to only one of them?

Maybe the easiest way would be to use some dos2unix converter in the pipe, like "for db in `dos2unix /etc/oratab|egrep ...`

^M is the MS-DOS/Windows end-of-line sign. Pipe the file through some converter, i.e. use dos2unix (ask manpage for params) instead of cat

Yes, but why does it work fine from the command line then? I think it's a syntax error in some way.

It's not allowed to bump up questions! Please read the rules:

It turned out to be my Windows editor causing the problem. I was FTP'ing the file back to Unix after the edit. It's working great now.

Thanks for your help!