O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

You must make note of two things in this recipe:

  1. Change the working directory of the process to the location of the shell script.
  2. Use /bin/bash to execute the shell script. 

If you don't do step 1, then you'll have to use the absolute path for the shell script file. However, in the recipe, we did do step 1, and hence, we just use the shell script name for the /bin/bash command.

Step 2 is basically how you would want to execute the shell script. The way to do so is to pass the shell script to the interpreter, which will interpret and execute the script. That is what the following line of code does:

pb.command("/bin/bash", "script.sh")

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required