I am totally new to scripting in linux...so i want to port some simple window bat files to ubuntu.
First file is easy
setenv.bat
set ANT_HOME=c:\ant\apache-ant-1.7.1
set JAVA_HOME=c:\java
in linux i did this and it seems ok
setenv.sh
#!/bin/bash
JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24/
ANT_HOME=/usr/share/ant
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
pause
but i have no clue how can i do this in linux call ../config/setenv
thank you for any help , direction given.
It would be:
#!/bin/sh
source ../config/setenv.sh
${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 setenv.sh 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:
https://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/unixscripting/unixscripting.html
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
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%
And another example: