Re: Execute permission of a file



It looks to me like it depends on whether it is a binary or a text file (script).

I did some simple testing:

I created a script that just echos "hi" and i copied the 'ls' command from /usr/bin to my home directory, I am not running as root but a regular user.
*----------------------------
# ls -l x.sh
-rwxr-xr-- 1 root sys 18 Jun 29 09:03 x.sh

(since Im not root or in the sys group my access to x.sh is read only).

# sh ./x.sh
hi

(I can run it in another shell as seen above)

# cat ./x.sh
#!/bin/sh
echo hi

(displaying its contents for you)

# ls -la ls
-rwxr-xr-- 1 root sys 25628 Jun 29 09:50 ls

(another file, a binary I copied from /usr/bin to my home, also read only access)

# sh ./ls
sh: ./ls: 0403-006 Execute permission denied.

(failed)

# file ./ls
./ls: executable (RISC System/6000) or object module

(proving its a binary)

#
*----------------------------

So if it is a script you can run it with 'sh' but if its binary you can not.

Is the shell smart enough to figure out that if the user can see the contents (because of the read access) of the script that they could very well run its contents separately?

This is completely unscientific though =)
-shawn


faisalq@xxxxxxxxxxxx 6/29/06 8:11:50 AM >>>
Dear all,

Pl. bear with me, it may be a very naive question.

If a user can execute any file using 'sh filename' - even though he doesn't have 'execute' permission, what is the significance of 'x' bit in unix?

A colleague asked this question, and i could not answer.


Thanks.