Need Simple Way To Determine If File Is Executable

S

Sebastian 'lunar' Wiesner

Marc 'BlackJack' Rintsch said:
There are other executable loaders for `a.out` and `COFF` in the
kernel, and with the `binfmt_misc` module you can make anything with a
"magic" header executable, including Python scripts/bytecode and even
JPEG images.

Yes, I know...
But ELF is actually the most common linker format on Linux systems.
a.out is a legacy format, that is afaik not used by any modern
distribution. Concerning COFF I'm not sure, if there is really a COFF
loader in the kernel. At least I did not find any information about
such a loader in the kernel configuration. It just lists elf, a.out and
binfmt_misc.

But basically you're right. One could even write a loader for JPEG
files.
But as long as such an loader is not part of a standard linux
distribution, nothing bad happens when you try to execute a JPEG file,
and that's what I wanted to point out.

Sebastian
 
F

Fredrik Lundh

Sebastian said:
???
Am I blind or is there really no difference between you shell example an
mine?
As far as I can see, you are doing exactly the same thing as I did...

no, I'm showing that a local file marked as executable overrides a
shared one, even if the local file isn't actually an executable.
So what are trying to proof?

that you're wrong when you claim that the contents of the file matters
when using the usual Unix conventions to check if a file is executable.

maybe you should read Tim's post and the post he replied to again?

</F>
 
P

Paul Arthur

no, I'm showing that a local file marked as executable overrides a
shared one, even if the local file isn't actually an executable.

Only if you have your system set up badly. The current directory should
not be in the search path, and it especially shouldn't have higher
priority than the regular bin locations.
 
F

Fredrik Lundh

Paul said:
Only if you have your system set up badly. The current directory should
not be in the search path, and it especially shouldn't have higher
priority than the regular bin locations.

and the award for completely missing the context of this subthread goes
to...

</F>
 
S

Sebastian 'lunar' Wiesner

Fredrik Lundh said:
and the award for completely missing the context of this subthread
goes to...

Nevertheless his comment was absolutely correct...
 
F

Fredrik Lundh

Sebastian said:
Nevertheless his comment was absolutely correct...

nope. a Unix system uses the same flag to determine if a file is
executable no matter how I've set up my path.

</F>
 
S

Sebastian 'lunar' Wiesner

Fredrik Lundh said:
nope. a Unix system uses the same flag to determine if a file is
executable no matter how I've set up my path.

Paul didn't even mention the word "executable". He was referring to
completely different thing: The fact, that whether a local executable
overrides a shared on, is matter of how you set your PATH. The local
file would be executable, whether it is in the PATH or not...
 
S

Sebastian 'lunar' Wiesner

Fredrik Lundh said:
no, I'm showing that a local file marked as executable overrides a
shared one, even if the local file isn't actually an executable.

Well, that doesn't tell us anything about, whether a file executable or
not.
But anyway: you admit, that the local file "ls" is __not__ actually
executable, although it has the x-bit set?
that you're wrong when you claim that the contents of the file matters
when using the usual Unix conventions to check if a file is
executable.

Let me ask you a question:

[lunar@nargond]-[13:09:52] >> ~/test
--> cat test.sh
#!/bin/bash

if [ "$1" ]; then
echo "Hello $1"
else
echo "Hello world"
fi

[lunar@nargond]-[13:09:54] >> ~/test
--> ll test.sh
-rw-r--r-- 1 lunar lunar 76 2006-12-21 13:09 test.sh

Is test.sh now executable or not?

Bye
lunar
 
F

Fredrik Lundh

Sebastian said:
Paul didn't even mention the word "executable". He was referring to
completely different thing: The fact, that whether a local executable
overrides a shared on, is matter of how you set your PATH. The local
file would be executable, whether it is in the PATH or not...

are you trying to win some kind of award?

</F>
 
T

Tim Roberts

Sebastian 'lunar' Wiesner said:
...
Well, that doesn't tell us anything about, whether a file executable or
not.
But anyway: you admit, that the local file "ls" is __not__ actually
executable, although it has the x-bit set?

Sebastian, you really have missed the point of this thread. The original
question was "how can I find out if a file is executable". The answer
involved calling stat. On a Linux system, using stat, the definition of
"executable" is "has the x mode bit set". On a Windows system, using stat,
the definition is "has an extension that is in PATHEXT". Nothing more,
nothing less. In both cases, the contents of the file are irrelevant.

Now, when you, as a human being, try answer the question "is this file
executable", you would use more sophisticated criteria that looked at the
first bytes of the file, but that's not the question here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top