Reference all paths in single linux script - like a header file for better portability [closed]
Shell Scripting newbie here.
Please bear with me.
Linux 3.0.101-108.87-default x86_64
I have Script1.sh which is referencing folders . I am trying to include all these paths in the script in a single headerscript.sh and then reference the headerscript.sh in Script1.sh
I am doing this right now
Script1.sh
setenv SCRIPT /../site/SCRIPTS
setenv TOP /../site/TOP
setenv SUB1 /../site/../.../SUB1
setenv SUB2 /../site/../.../SUB2
setenv SUB3 /../site/../.../SUB3
setenv SUB4 /../site/../.../SUB4
setenv SUB5 /../site/../.../SUB5
Instead I want to do something like this
Script1.sh
include headerscript.sh
and headerscript.sh will look something like this
headerscript.sh
setenv SCRIPT /../site/SCRIPTS
setenv TOP /../site/TOP
setenv SUB1 /../site/../.../SUB1
setenv SUB2 /../site/../.../SUB2
setenv SUB3 /../site/../.../SUB3
setenv SUB4 /../site/../.../SUB4
setenv SUB5 /../site/../.../SUB5
This allows me to make the script modular by just including headerscript.sh in another script and easier to debug.
What should I be doing ?
I don't want to include this in .alias
To "include" one script from another you should use .
(dot operator) or source
(depending on your shell).
So you would use in Script1.sh
. headerscript.sh
References:
https://unix.stackexchange.com/questions/309768/source-vs-why-different-behaviour
https://stackoverflow.com/questions/20094271/using-dot-or-source-while-calling-another-script-what-is-the-difference
https://ss64.com/bash/source.html#:~:text=source%20is%20a%20synonym%20for,available%20after%20the%20script%20completes.