syntax error running shell program in bash (Centos 5.9)

Posted on 2014-01-18
Last Modified: 2014-01-18

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 line 44: syntax error: unexpected end of file

Open in new window

# Please source this file.

#setenv PATH /x/contrib/j2sdk1.4.0/jre/bin:$PATH
#setenv PATH /usr/lib/jvm/java-1.7.0-openjdk-$PATH
export PATH=/usr/lib/jvm/java-1.7.0-openjdk-$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
        echo cannot find crypto distribution ...
        exit 1

#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/jaxrpc.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

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:

Thank you,
Question by:Victor Kimura
LVL 25

Assisted Solution

by:Tomas Helgi Johannsson
Tomas Helgi Johannsson earned 125 total points
ID: 39790522

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


for CLASSPATH example
Make sure that you have the AXIS_HOME variable set correctly.

  Tomas Helgi
LVL 19

Assisted Solution

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"
LVL 68

Assisted Solution

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"
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!


Author Comment

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

Accepted Solution

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

Open in new window

same in bash:
if condition; then
elif cond; then

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
        echo cannot find crypto distribution ...
        exit 1

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
        echo cannot find crypto distribution ...
        exit 1
export CLASSPATH=.

Open in new window

Note that exports are *outside* of shell invocation but the conditional structure is *inside*.

Author Closing Comment

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

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weird Samba Connectivity Issue... 7 39
Coding C# in Linux 8 60
awk sed variable in file 3 34
How to check currently configured static routes on CentOS 7? 1 18
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…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now