Monday, August 21, 2017

how to call a shell script from another

There are a couple of ways you can do this:
  1. Make the other script executable, add the #!/bin/bash line at the top, and the path where the file is to the $PATH environment variable. Then you can call it as a normal command.
  2. Call it with the source command (alias is .) like this: source /path/to/script.
  3. Use the bash command to execute it: /bin/bash /path/to/script.
The first and third methods execute the script as another process, so variables and functions in the other script will not be accessible.
The second method executes the script in the first script's process, and pulls in variables and functions from the other script so they are usable from the calling script.
In the second method, if you are using exit in second script, it will exit the first script as well. Which will not happen in first and third methods.

source from:
https://stackoverflow.com/questions/8352851/how-to-call-shell-script-from-another-shell-script

No comments:

Post a Comment