-2

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?

Uberhumus
  • 921
  • 1
  • 13
  • 24
  • Find's exec executes commands. Dot (`.`) and `source` are shell builtins, see here: https://unix.stackexchange.com/a/109222 BTW, in your example with find `.` is interpreted as the current directory, which is probably not what you want. – alagner Aug 28 '23 at 06:42
  • They do not behave differently in `bash`. `bash`has nothing to do with it. You aren't executing `bash` at all here. You are attempting to execute (1) `.` and (2) `source`. Neither succeeded, for the reasons shown. Off topic. – user207421 Aug 28 '23 at 06:57
  • Should I and can I move this question to a different stackexchange, and if so how? @user207421 – Uberhumus Aug 28 '23 at 08:43

1 Answers1

2

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.

Ljm Dullaart
  • 4,273
  • 2
  • 14
  • 31