bug-bash
[Top][All Lists]
Advanced

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

Re: RFE & RFC: testing executability


From: Pierre Gaston
Subject: Re: RFE & RFC: testing executability
Date: Mon, 2 Oct 2017 08:50:33 +0300

On Sun, Oct 1, 2017 at 7:31 AM, L A Walsh <bash@tlinx.org> wrote:

> 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
>

Besides the fact that most people don't use alias in script where it would
be the only place where such a feature would really be valuable, I think
the main problem is that alias can contain pretty much anything, from
loops, partial code etc..

What should be the result of -x in the  following case?

alias f='for i in 1 2;do echo foo;done'
alias g='if true; then'
alias h='true;missing_command'

Should it be recursive?
alias j=f

In my opinion the feature you describe is pretty much tailored to your
specific need but it is probably hard to give it a really more general and
sensible meaning.


reply via email to

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