rmyorston / busybox-w32

WIN32 native port of BusyBox.
https://frippery.org/busybox
Other
693 stars 126 forks source link

I want to check the existence of file.exe with test -x file #469

Open vj23a opened 4 hours ago

vj23a commented 4 hours ago

Nice to meet you. Can't you check the existence of file.exe using test -x file?

Example:

touch file.exe
test -x file; echo $?
0 -> 1

Please

rmyorston commented 3 hours ago

Sure, test -x tests if a file exists and appears to be executable. It returns an exit code of 0 when the test succeeds.

~ $ touch file.exe
~ $ ls -l file.exe
-rwxrwxr-x    1 rmy      rmy              0 Oct 26 15:05 file.exe
~ $ if test -x file.exe; then echo 'it exists'; fi
it exists
~ $

Of course, an empty file isn't really executable:

~ $ ./file.exe
sh: ./file.exe: Exec format error
~ $

It just appears to be executable to test because busybox-w32 treats any file with the extension .exe as having execute permission.