LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   syntax error near unexpected token `then' (https://www.linuxquestions.org/questions/linux-server-73/syntax-error-near-unexpected-token-%60then-789533/)

snakernetb 02-16-2010 01:04 PM

syntax error near unexpected token `then'
 
Hi all, I am trying to build a script that runs on AIX, Solaris, and various flavors of Linux as well. It is very simple, or so I thought. I have the AIX and Solaris servers working well. Next I tried to get my workstation to run the script and it bombed. I am running Fedora 12 x86_64, but that isn't really important. I have various flavors of Linux. Some CentOS, RH, and even a Gentoo server. The script I have runs every hour on all servers. I can push out changes and install software with it, but the Linux WS won't run it. Here is my script:

uname=`uname`
os1="AIX"
os2="SunOS"
os3="Linux"
#echo $oslevel
if [[ $uname = $os1 ]] then
/tools/HourlyProcess/HourlyProcess_Kickoff_AIX
fi
if [[ $uname = $os2 ]] then
/tools/HourlyProcess/HourlyProcess_Kickoff_Sun
fi
if [[ $uname = $os3 ]] then
/tools/HourlyProcess/HourlyProcess_Kickoff_Linux
fi
exit

And here are the errors:

/tools/HourlyProcess/HourlyProcess_Kickoff: line 6: syntax error near unexpected token `then'
/tools/HourlyProcess/HourlyProcess_Kickoff: line 6: `if [[ $uname = $os1 ]] then'

Is this just an issue with going between ksh and bash?

catkin 02-16-2010 01:10 PM

Either put a ";" after the "]]" and before the "then" or put the "then" on another line.

snakernetb 02-16-2010 01:32 PM

That got it
 
Thanks, in troubleshooting the Solaris portion I had to remove the #!/bin/ksh at the top of the script. I doing all of that I also removed the ; before the then as well. It is working everywhere now, I didn't even notice that was gone until you brought it up.

chrism01 02-16-2010 06:30 PM

You can get the real ksh on Linux these days, so I'd specify that at the top again (check the paths on each OS).
You don't want to assume that the 'default' shell will always be ksh (or whatever).

jschiwal 02-16-2010 06:40 PM

You may not be able to know whether ksh is in /bin, /usr/bin or /usr/local/bin. For ksh scripts to run on all *nixes, they usually start:
#!/usr/bin/env ksh


All times are GMT -5. The time now is 04:48 AM.