I have a script file which refers to another script file(containing some functions) this way:
. "${scripts_dir}/update.sh"
What does it mean in linux scripting?
Does it load code in update.sh so that it can be invoked now onwards?
I have a script file which refers to another script file(containing some functions) this way:
. "${scripts_dir}/update.sh"
What does it mean in linux scripting?
Does it load code in update.sh so that it can be invoked now onwards?
.
is a command (!) that sources the indicated script.
Sourcing means executing the script, but in context of currently running shell. If you "normally" execute a script from another script, then a separate shell instance (called a subshell) is used to execute the second script.
This is used usually if you want to set some shell variables or environment variables, define functions or aliases etc. in the second script. In case of "normal" execution, they won't be passed back to the first script, but with sourcing it is possible.
Also an important difference occurs if the command exit
is used in the second script. In case of "normal" execution, this ends the second script (to be precise, exits the shell that executes the second script, which obviously causes the script to terminate), but the first script continues to run from the next command after the call to second script. However if exit
is used in a second script that is sourced, it ends both scripts at this point (because it exits the shell that is executing the first script).
.
is not an executable but a shell builtin.
– raj
Aug 23 '23 at 11:59