Solved

syntax error running shell program in bash (Centos 5.9)

Posted on 2014-01-18
6
1,131 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

636 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