Yes, source executes script differently, I mean, in a different shell
Objective
See how differently shell script is executed using source
.
1. Basic
source
command executes the provided script (executable permission is not mandatory) in the current shell environment, while ./
executes the provided executable script in a new shell.
source
command do have a synonym. filename
.
To make it more clear, have a look at the following script, which sets the alias, using a shell script file named, make_alias
.
2. make_alias
file
3. Two options
Now we have two choices to execute this script. But with only one option, the desired alias for your current shell can be created among these two options.
3.1. Option 1 ./make_alias
Make script executable first.
3.1.1. Execute
3.1.2. Verify
3.1.3. Output
no alias for myproject
Whoops!, alias is gone with the new shell.
Now, let’s go with the second option.
3.2. Option 2 source make_alias
No need to make script executable while using
source
.
3.2.1. Execute
or
3.2.2. Verify
3.2.3. Output
Yeah, alias is set now.