Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script dosn't work in Redhat Linux Ver 4

Status
Not open for further replies.

swaroop

Programmer
Feb 4, 2001
100
0
0
US
All,

echo ${DEBUG_PORT}
if [ "${DEBUG_PORT}" == "" ] ; then
DEBUG_PORT="8453"
export DEBUG_PORT
echo " FINALLY I AM HERE "
echo ${DEBUG_PORT}
fi


The above Script is in a file named test.sh I am trying to run it. It dosn't print 8453 at first.

I am running the script as ./test.sh

OS is Redhat Linux Ver 4.

Any ideas?

Thanks in advance.

Swaroop Kunduru.
 
If you want that Environment Variable to remain consistent, try putting it in your .bash_profile.

Not sure why it is not sticking.
 
I've often seen an idiom like this:
Code:
if [ "a"${FOO} == "a" ] ; then
and guessed, comparing to some kind of null is a problem, but I don't know whether this is true for '== ""' too.


seeking a job as java-programmer in Berlin:
 
I don't readily see anything wrong, but try this way, just to give you a different perspective:
Code:
echo "Debug Port: |$DEBUG_PORT|"
if [ "x$DEBUG_PORT" == "x" ]; then
    DEBUG_PORT="8453"

    # The following line doesn't do anything unless the
    # script is sourced in to the current shell
    export DEBUG_PORT 

    echo "New Debug Port: |$DEBUG_PORT|"
fi

I think stefan is on to something. I know I've seen some wierdness when it comes to comparing to an empty string, but I can't duplicate that now.

The curly brackets are actually good practice. Stick them back in there if you want to. I personally don't like to use them.

Note that the value of the variable will go away after the script is done running. You will have to source it into your current environment in order to keep the variable. This is what clonny was referring to.

For example, if your script is named [tt]portme.sh[/tt], this will source it in:
Code:
. portme.sh

--
-- Ghodmode
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top