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

Getting ready

First, let's write our shell script. This script does the following:

  1. Print the value of the environment variable, MY_VARIABLE.
  2. Execute the tree command.
  3. Execute the iostat command.

Let's create a shell script file by the name, script.sh, with the following commands in it:

echo $MY_VARIABLE;
echo "Running tree command";
tree;
echo "Running iostat command"
iostat;

You can place the script.sh in your home folder that is, in the /home/<username>. Now let's see how we can execute this from Java.

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