Here is the way to start another script in a shell script. The purpose is entire logic can keep in one place, and it is easy to maintain.

You May Also Like | UNIX: How to Use Sed and AWK Commands

The project is to convert US dollars into Indian rupee (assuming 1 USD = 70 INR.). Here are two scripts for this purpose.

  1. conversion.sh
  2. display_currency.sh

Start another script in a shell script

I’ve added conversion logic in this script. And I’ve passed the output to called script.

Here's my first script conversion.sh
A script calling from another script

I’ve initialized the value conv_factor=70. For calculation, I used the let command. The output I’ve saved to converted_rupees.

I’ve used the export command to pass value to the called script, which I used for display. The way I showed here simplifies calling a script from another script. So it is easy to maintain them.

Here’s the output of the scripts

In this video, you can see the execution of both scripts.

Here’s the output of the scripts

Summary

  • You can call a script from another script
  • Use the let command to calculate math-related things (computation)
  • Export command