Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

syntax error running shell program in bash (Centos 5.9)

Posted on 2014-01-18
6
Medium Priority
?
1,146 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
6 Comments
 
LVL 26

Assisted Solution

by:Tomas Helgi Johannsson
Tomas Helgi Johannsson earned 500 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 500 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 500 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

1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

927 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