Here’s the Real Reason to Include Script in Another Script

In Bash shell, here’re the reasons to include the script in another – The entire logic you can avoid in one and easy maintenance.

Read: UNIX: How to Use Sed and AWK Commands

I have a project to convert US dollar into Indian rupee assuming 1 USD = 70 INR. I have written two scripts for this purpose.

  1. conversion.sh
  2. display_currency.sh

Here’s my first script conversion.sh

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

Here's my first script conversion.sh

I’ve initialized 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 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.

Read: 3 File Descriptors in Unix Operating System: What They Mean

Here’s the output of scripts

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

Here’s the output of scripts

Summary

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

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.