Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why and when do source and dot behave differently in Bash

I have heard it said multiple times that in Bash source is merely an alias for .. Even in the Bash man page. However, I’ve noticed, while digging into this question that they are not identical when called via find. Here is a reproducible example:

I’ve created a file called test.sh

uberhumus@pc:~/tmp$ cat ./test.sh
#!/bin/bash

echo "Kazabooboo"
uberhumus@pc:~/tmp$ find ~/tmp -type f -iname "test.sh" -exec . {} \;
find: ‘.’: Permission denied
uberhumus@pc:~/tmp$ ind ~/tmp -type f -iname "test.sh" -exec source {} \;
find: ‘source’: No such file or directory

So my question is what causes the difference, and are there any other differences?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In bash, source and . are the same, as the man page says.

What you are doing here is testing if find treats source and . the same way. It does not. find understands that . is the current directory. You cannot exec the current directory; permission is denied.

if find needs to execute source, there must be an external program source available. There is none in your PATH, so you get No such file or directory

The fact that they are different for find does not imply that there is a difference for bash.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading