[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFE & RFC: testing executability

From: PePa
Subject: Re: RFE & RFC: testing executability
Date: Mon, 2 Oct 2017 15:05:07 +0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0

On 10/01/2017 11:31 AM, L A Walsh wrote:
cmd=$(PATH=/stdpath type -p cmd)

I use this kind of construction with 'type -p' regularly:

! cmd=$(type -p cmd) && echo "ABEND: Executable cmd not in PATH" && exit

Then $cmd can be used to execute the binary, and not some alias or function. This is the whole point of the '-p' flag, otherwise you would use the '-a' flag. When 'cmd' is in the PATH, it is found even when it isn't executable, so it could make sense to do 'text -x "$cmd".

> the "-x" test failed if cmd was an alias, function or preceded by
> 'command' (which I was surprised, also, to find, "not executable").

Note that 'test -x' only tests actual files, so if you do 'test -x grep' and there is no executable file 'grep' in $PWD then it tests false.

> Comments?  Reasonable?  Wanted? Doable or patchable?

It follows that you cannot use 'test -x' on functions or aliases, as they are not files. I don't understand your use case. Do you want a 'type -a' kind of functionality? What do you want to test?? I think you can already do what you need in bash.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]