I am trying to learn Bash, and I came across source
- very handy. However, when I tried to use source
from scripts in different folders and created by different users, it suddenly didn't work. While searching online, I learned about .
(a period). It's supposed to be a synonym of source
, but I tried changing just for the sake of it. And it worked. So now I'm curious.
What is the difference between:
source
and
.
If really none, am I just imagining things?
The essential difference between the two is: An opportunity's origin tells you the means by which it entered the pipeline. An opportunity's source tells you the action(s) or location(s) that generated it.
Executing a script will run the commands in a new shell process. Changes to the environment take effect in the new shell and is lost when the script is done and the new shell is terminated. Use source if you want the script to change the environment in your currently running shell. use execute otherwise.
Source refers to a place or origin from where something is obtained. A resource refers to materials, staff, supplies and other assets that are needed for something to function effectively. This is the main difference between source and resource.
To source a script is to run it in the context of the current shell rather than running it in a new shell. For example: . myscript.sh. or: source myscript.sh. (depending on which shell you're running).
In bash
, they are synonymous.
See https://askubuntu.com/questions/25488/what-is-the-difference-between-source-and-in-bash
About other flavors of shells, they may only have .
, so source
may be considered a bashism.
(Which is kinda too bad, I find source
more readable than .
, though I suppose we wouldn't use bash
for maximum readability.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With