syntax error running shell program in bash (Centos 5.9)

Hi,

I'm trying to run this simple shell program. I'm new to the shell programming but it was downloaded from the Paypal site for helping set up encrypting buttons.

Here's there error:

bash set_classpath2.sh
set_classpath2.sh: line 44: syntax error: unexpected end of file

Open in new window


#/bin/csh
# Please source this file.

#setenv PATH /x/contrib/j2sdk1.4.0/jre/bin:$PATH
#setenv PATH /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25/jre/bin:$PATH
export PATH=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25/jre/bin:$PATH

#setenv CRYPTO_HOME "../crypto-124"
#setenv CRYPTO_HOME "/home/myultrat/ssl/paypal/crypto-150"
export CRYPTO_HOME=/home/myultrat/ssl/paypal/crypto-150

if (-d $CRYPTO_HOME) then
	echo setting crypto home to $CRYPTO_HOME
else	
        echo cannot find crypto distribution ...
        exit 1
endif

#setenv CLASSPATH "."
#setenv CLASSPATH "${CLASSPATH}:${AXIS_HOME}/lib/axis.jar"
#setenv CLASSPATH "${CLASSPATH}:${AXIS_HOME}/lib/jaxrpc.jar"
#setenv CLASSPATH "${CLASSPATH}:${AXIS_HOME}/lib/saaj.jar"
#setenv CLASSPATH "${CLASSPATH}:${AXIS_HOME}/lib/wsdl4j.jar"
#setenv CLASSPATH "${CLASSPATH}:${AXIS_HOME}/lib/commons-logging.jar"
#setenv CLASSPATH "${CLASSPATH}:${AXIS_HOME}/lib/commons-discovery.jar"
#setenv CLASSPATH "${CLASSPATH}:${CRYPTO_HOME}/jars/bcprov-jdk14-124.jar"
#setenv CLASSPATH "${CLASSPATH}:${CRYPTO_HOME}/jars/bcpg-jdk14-124.jar"
#setenv CLASSPATH "${CLASSPATH}:${CRYPTO_HOME}/jars/bctest-jdk14-124.jar"
#setenv CLASSPATH "${CLASSPATH}:${CRYPTO_HOME}/jars/bcmail-jdk14-124.jar"
#setenv CLASSPATH "${CLASSPATH}:./ppapi.jar"

export CLASSPATH=.
export CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/axis.jar
export CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/jaxrpc.jar
export CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/saaj.jar
export CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/wsdl4j.jar
export CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/commons-logging.jar
export CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/commons-discovery.jar
export CLASSPATH=$CLASSPATH:$CRYPTO_HOME/jars/bcprov-jdk14-124.jar
export CLASSPATH=$CLASSPATH:$CRYPTO_HOME/jars/bcpg-jdk14-124.jar
export CLASSPATH=$CLASSPATH:$CRYPTO_HOME/jars/bctest-jdk14-124.jar
export CLASSPATH=$CLASSPATH:$CRYPTO_HOME/jars/bcmail-jdk14-124.jar
#echo $CLASSPATH

Open in new window


What's wrong with the code? Sorry, I commented out the setenv command lines because it didn't run in bash. I read this:
http://www.cyberciti.biz/faq/unix-linux-adding-path/

Thank you,
Victor
Victor KimuraSEO, Web DeveloperAsked:
Who is Participating?
 
SurranoConnect With a Mentor System EngineerCommented:
woolmilkporc is correct. However NickUpson is also correct in a sense that this particular script makes no sense if invoked in an embedded shell. It echoes something in if-else, but the export CLASSPATH part will have no effect since it loses its scope when the script exits. I.e. you *must* source this instead of executing, as visible in second line's hint.

The conditional structure in csh is:

if condition then
...
else if cond then
...
else 
....
endif

Open in new window


same in bash:
if condition; then
...
elif cond; then
...
else
...
fi

Open in new window


I.e. keywords are different and semicolon is a *must* in bash.
Note also that the test is [ ... ] in bash (the opening bracket is actually a shell builtin), i.e.:

But I recommend using "test" instead which is either a shell builtin or a binary executable (or both), thus independent from the shell and has the same syntax:

if  test -d $CRYPTO_HOME; then
	echo setting crypto home to $CRYPTO_HOME
else	
        echo cannot find crypto distribution ...
        exit 1
fi

Open in new window


The only blocking point is the existence of semicolon; it is needed in bash but not needed in csh. I don't know if it works in csh with semicolon as well. You may work around using && and ||

test -d $CRYPTO_HOME && echo setting crypto home to $CRYPTO_HOME
test -d $CRYPTO_HOME || (
    echo cannot find crypto distribution ...
    exit 1
)

Alternatively you may make it a mule:

# Please source this file.
...
export CRYPTO_HOME=/home/myultrat/ssl/paypal/crypto-150

/bin/csh -c "if (-d $CRYPTO_HOME) then
	echo setting crypto home to $CRYPTO_HOME
else	
        echo cannot find crypto distribution ...
        exit 1
endif
"
...
export CLASSPATH=.
export CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/axis.jar

Open in new window


Note that exports are *outside* of shell invocation but the conditional structure is *inside*.
0
 
Tomas Helgi JohannssonConnect With a Mentor Commented:
Hi!

To set an env variable you will need to to it like this

VARIABLE=...
VARIABLE=$VARIABLE....
export VARIABLE

for CLASSPATH example
 CLASSPATH=.
 CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/axis.jar
 CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/jaxrpc.jar
 CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/saaj.jar
 CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/wsdl4j.jar
 CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/commons-logging.jar
 CLASSPATH=$CLASSPATH:$AXIS_HOME/lib/commons-discovery.jar
 CLASSPATH=$CLASSPATH:$CRYPTO_HOME/jars/bcprov-jdk14-124.jar
 CLASSPATH=$CLASSPATH:$CRYPTO_HOME/jars/bcpg-jdk14-124.jar
 CLASSPATH=$CLASSPATH:$CRYPTO_HOME/jars/bctest-jdk14-124.jar
 CLASSPATH=$CLASSPATH:$CRYPTO_HOME/jars/bcmail-jdk14-124.jar
 export CLASSPATH
Make sure that you have the AXIS_HOME variable set correctly.

Regards,
  Tomas Helgi
0
 
Nick UpsonConnect With a Mentor Principal Operations EngineerCommented:
this is designed to be csh not bash, but it should invoke csh when run from bash

please try running as "source set_classpath2.sh"
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
woolmilkporcConnect With a Mentor Commented:
Since line 1  reads "#/bin/csh" instead of "#!/bin/csh" the script will be executed by your login shell, or, as you invoked it, by bash, and not by csh.

If this is what you desire please note that bash does not understand "endif" - it should be "fi"
0
 
Victor KimuraSEO, Web DeveloperAuthor Commented:
Hi @Thomas, Is that setting the env for bash or csh or both?
0
 
Victor KimuraSEO, Web DeveloperAuthor Commented:
Thank you all! That works! @Surrano, @woolmilkporc, @NickUpson, @TomasHelgi! =)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.