Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

how do I set an environment variable in my .profile file that takes into account if the variable exists and appends to it?

To explain:

I want to do

export ANT_OPTS=-Dparam=value 

but if the ANT_OPTS already exists I want to append to it.

I want to do something similar to

set ANT_OPTS=%ANT_OPTS% -Dparam=value 

in Windows.

How do I create it or append to it if it already exists?

share|improve this question
up vote 2 down vote accepted

Try

export ANT_OPTS="$ANT_OPTS -Dparam=value"

share|improve this answer
    
it worked like a charm. I was trying export ANT_OPTS=$ANT_OPTS -Dparam=value but it didn't work. It didn't occur to me to also add the quotes. Thanks! – user12345 Aug 26 '10 at 7:27
    
You're welcome Please mark the answer as accepted, then. :) – Janne Pikkarainen Aug 26 '10 at 7:31
    
Done! Thanks again! – user12345 Aug 26 '10 at 7:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.