u3l
u3l

Reputation: 3412

Difference between source and './' with respect to permissions in bash?

I have a simple executable shell file testperm.sh with permissions -rw-------@.

When I execute source testperm.sh or . testperm.sh, the file executes and prints Hello..........., as it should.

However, if I run ./testperm.sh, I get -bash: ./testperm.sh: Permission denied. Why is that permission is denied with this command, but with source it works fine?

(I'm referring to the bash shell on OS X by the way)

Upvotes: 0

Views: 101

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 81042

The difference between source testperm.sh/. testperm.sh and ./testperm.sh is like the difference between ls /bin/bash and /bin/bash.

The former in each pair is using the file as an argument to some other command.

The latter in each pair is using the file as the command to run.

Running a command requires executable permission. Using a file as an argument does not.

Upvotes: 1

Related Questions