Is there a difference between "." and "source" in bash, after all?
Posted
by
ysap
on Ask Ubuntu
See other posts from Ask Ubuntu
or by ysap
Published on 2012-08-30T01:07:33Z
Indexed on
2012/08/30
3:49 UTC
Read the original article
Hit count: 366
I was looking for the difference between the "." and "source" builtin commands and a few sources (e.g., in this discussion, and the bash manpage) suggest that these are just the same.
However, following a problem with environment variables, I conducted a test. I created a file testenv.sh
that contains:
#!/bin/bash
echo $MY_VAR
In the command prompt, I performed the following:
> chmod +x testenv.sh
> MY_VAR=12345
> ./testenv.sh
> source testenv.sh
12345
> MY_VAR=12345 ./testenv.sh
12345
[note that the 1st form returned an empty string]
So, this little experiment suggests that there is a difference after all, where for the "source" command, the child environment inherits all the variables from the parent one, where for the "." it does not.
Am I missing something, or is this is an undocumented/deprecated feature of bash?
[ GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu) ]
© Ask Ubuntu or respective owner