Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "source" and "."

Tags:

bash

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?

like image 290
Paolo Avatar asked Jul 18 '13 13:07

Paolo


People also ask

What is difference between source and origin?

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.

What is difference between source and Bash?

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.

What is the difference between source?

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.

What does it mean to source a script?

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).


1 Answers

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.)

like image 57
Prashant Kumar Avatar answered Sep 30 '22 15:09

Prashant Kumar