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

I am totally new to scripting in i want to port some simple window bat files to ubuntu.

First file is easy

    set ANT_HOME=c:\ant\apache-ant-1.7.1
    set JAVA_HOME=c:\java

in linux i did this and it seems ok
    echo $JAVA_HOME
    echo $ANT_HOME

but now i want to port this bat file: startserver.bat

call ../config/setenv

call %ANT_HOME%/bin/ant -f ../config/common.xml start_db
call %ANT_HOME%/bin/ant -f ../config/common.xml start_server


but i have no clue how can i do this in linux call ../config/setenv

thank you for any help , direction given.

share|improve this question
ok thanks ...will start reading this docs. – Cris Jun 24 '11 at 22:38
up vote 5 down vote accepted

It would be:

source ../config/
${ANT_HOME}/bin/ant -f ../config/common.xml start_db
${ANT_HOME}/bin/ant -f ../config/common.xml start_server

source will make the variables which are set in available to your current script.
${ANT_HOME}/bin/ant will execute the ant binary.
The pause will just wait so that the cmd.exe window doesn't close, I'd suggest not to port that.

Anyway, this is all really basic stuff, take a look at some basic shell scripting tutorials like:

share|improve this answer
.//usr/share/ant/bin/ant is a nonsense path, there shouldn't be a ./ before the variable – DerfK Jun 24 '11 at 22:30
You are of course correct, edited. Thanks. – faker Jun 24 '11 at 22:37
 cd /path/to/working/directory
 source ../config/setenv
 $ANT_HOME/bin/ant -f ../config/common.xml start_db
 $ANT_HOME/bin/ant -f ../config/common.xml start_server
 sleep 10

Once you're in a script you can call scripts directly - however the problem with this is that all the calls are relative. That's fine if you can be sure of that - so what you can do is add a command to make sure of that - cd /path/to/working/directory

share|improve this answer
Does this actually work? the script doesn't export the variables and you're not sourcing the script – ptman Jun 24 '11 at 22:29
Correct I should have sourced setenv – BZ. Jun 24 '11 at 22:34

if you want to pull in those environment variables use the keyword "source" (aka '.') instead of call

for starting the programs you don't need to prefix "call"

additionally variables are referenced by $variablename instead of %variablename%

share|improve this answer

And another example:


export JAVA_HOME=/usr/lib/jvm/java-6-sun-
export ANT_HOME=/usr/share/ant

$ANT_HOME/bin/ant -f ../config/common.xml start_db
$ANT_HOME/bin/ant -f ../config/common.xml start_server
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.