bug-bash
[Top][All Lists]
Advanced

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

RFE & RFC: testing executability


From: L A Walsh
Subject: RFE & RFC: testing executability
Date: Sat, 30 Sep 2017 21:31:20 -0700
User-agent: Thunderbird

I was looking at a script that tested command for execute before
executing them.
The script used:

 cmd=$(PATH=/stdpath type -p cmd)

and later tested executability with "-x $cmd", raising 2 problems. The first was "-p" returning empty if "cmd" was an alias or
function.  Second was that even if "-P" was used, the "-x" test failed
if cmd was an alias, function or preceded by 'command' (which I was
surprised, also, to find, "not executable").

I realize that -x is probably only looking for whether or not the OS
considers its "object" to be executable, but it seems that a modern
shell (like bash) might also include *its* *own* "objects", that it
knows to be either executable or equivalent.  I can think of 3 cases
where the shell could do better in assessing executability than it
is today:

First: if we have a function: by definition, a function is
"executable".  Regardless of its contents, it is executable shell
script and I would prefer (and have least surprise) if functions
were always considered to be "executable" (with "-x" returning
true).

A second case: an alias could be seen (and tested) as similar to
variable access:

I.e. if an alias pointed to an executable, e.g.
alias Ls=$(type -P ls)

I'd like to see the shell intelligent enough to do an executable
test on :
-x "${BASH_ALIASES[Ls]}"


and thirdly, testing, *either*, whether the object of a "command <cmd>"
is executable (preferred) -- i.e. testing '<cmd>',
*or* evaluating "command" as always being executable (-x = "always true")
on the premise that command is used to invoke an executable program (circumventing any aliases or functions).


Comments?  Reasonable?  Wanted? Doable or patchable?

-linda





reply via email to

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