LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Porting ksh script from Solaris to Linux Gives unmatched if error (https://www.linuxquestions.org/questions/programming-9/porting-ksh-script-from-solaris-to-linux-gives-unmatched-if-error-665859/)

markatharvestinfotec 08-27-2008 02:53 PM

Porting ksh script from Solaris to Linux Gives unmatched if error
 
Following is my script,which works perfectly fine on Solaris ksh, but when trying to run on RHEL 4 ksh, it gives the following error
upgrade.sh[4]: syntax error: `if' unmatched

Is there anything special I need to do run on Linux.
I need your help badly, dont know what match if is missing

###
# DATABASE SCRIPTS
###
1. cd $upgradeDir
2. for dir in *
3. do
4. if [[ -d ${dir} ]] && ((${developmentUpgrade} && (( ${dir} >= ${currentRelease} ))) || (( ${dir} > ${currentRelease} )))
then
#echo "DIR: $dir"
cd ${dir}
for file in *.dll
do
if [[ -f ${file} ]];
then
executeCommand "${sqlCommand} @${file}"
fi
done
cd ..
fi
done

matthewg42 08-27-2008 03:22 PM

Please post scripts and other source code in [code] tags. This vastly improves readability by displaying with a fixed width font and preserving whitespace.

The 1. 2. 3. 4. beginnings to the lines are for what purpose? Are these supposed to be comments? If so you should start the line with a #, else you will get messages like this:
Code:

1.: not found [No such file or directory]
The syntax of the if statement on the line starting with "4." is all wrong (never mind the fact that the 4. will make the if statement useless). You seem to have many "(( ... ))" when you should have "[[ ... ]]". That it runs on Solaris is a surprise - as far as I can tell this is not valid syntax.

markatharvestinfotec 08-28-2008 10:48 AM

My apologies, I have modified the script below, so that it can run on your machine. It still giving me this error.
Line 9 : Syntax error near unexpected token 'fi'.
Let me try as you suggested.

Code:

developmentUpgrade=false
currentRelease=100
majorSeparator="=============================================================="
for dir in *
do
  if [[ -d ${dir} ]] && (  (${developmentUpgrade} && (( ${dir} >= ${currentRelease} ))) || (( ${dir} > ${currentRelease} )))
        #echo "DIR: $dir"
        echo "HELLO WORLD, I AM IN WORKING CONDITIONS"
    fi
done


matthewg42 08-28-2008 11:52 AM

I said that your if statement is incorrect. It is still incorrect. You cannot use normal brackets () - that is not valid shall syntax.

markatharvestinfotec 08-28-2008 01:51 PM

The script runs on Linux now
 
Thanks matthew :), The script works great, I had to play around and replace some (( with [[ ones. Here is the modifed code

Code:

developmentUpgrade=false
currentRelease=500
majorSeparator="=============================================================="
for dir in *
do
if [[ -d ${dir} ]] && ( (${developmentUpgrade} && (( ${dir} >= ${currentRelease} ))) || [[ ${dir} > ${currentRelease} ]] ) ; then
            echo "DIR: $dir"
        fi
done



All times are GMT -5. The time now is 09:09 PM.