Solved

syntax error running shell program in bash (Centos 5.9)

Posted on 2014-01-18
6
1,122 Views
Last Modified: 2014-01-18
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
0
Comment
Question by:Victor Kimura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 25

Assisted Solution

by:Tomas Helgi Johannsson
Tomas Helgi Johannsson earned 125 total points
ID: 39790522
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
 
LVL 19

Assisted Solution

by:NickUpson
NickUpson earned 125 total points
ID: 39790526
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
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 125 total points
ID: 39790553
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:Victor Kimura
ID: 39790585
Hi @Thomas, Is that setting the env for bash or csh or both?
0
 
LVL 8

Accepted Solution

by:
Surrano earned 125 total points
ID: 39790586
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
 

Author Closing Comment

by:Victor Kimura
ID: 39790603
Thank you all! That works! @Surrano, @woolmilkporc, @NickUpson, @TomasHelgi! =)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question