Why and when do source and dot behave differently in find -exec {}

53 views Asked by At

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

My question is what causes the difference, and are there any other differences that aren't discussed?

1

There are 1 answers

0
Ljm Dullaart On BEST ANSWER

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.