Friday, April 08, 2016

How to force java path in subscript (nested script call)

If you use a script that runs another script which starts a java virtual machine, you should need to specify which java command you want to use from the first script. Consider the following example :

startup.sh  --->  application.sh --> java command

I can modify startup.sh but not application.sh which calls java command. But I need a specify version a java.

So, I tried to solve this problem with :

  • linux 'source' command ... BAD!!!
  • linux 'alias' command... BAD!!!
But, I finally got a working solution by redefining a  'java' function before calling application.sh. GOT IT! When application.sh calls 'java', it invokes my function. Like this :


java() {
    /specificpath/jdk/bin/java "$@"
}
export -f java
sh ./application.sh


Enjoy!