This might suffice for the initial situation, as long as the expansion is
passed in with single quotes:

function check_n_run() {
    greo="$1"; wild="$2"
    if $(which "$greo" > /dev/null); then
        $greo $wild;
    fi
}

This is too cute to be useful, but it was enjoyable seeing the unintended
consequences when replace other, more used commands.

function greo() {
    wild="$@"
    if $(which "${FUNCNAME[0]}" > /dev/null); then
        $(which "${FUNCNAME[0]}") $wild
    fi
}



Dave Finlay


On Tue, Apr 22, 2014 at 1:03 PM, Chet Ramey <chet.ra...@case.edu> wrote:

> > On Mon, Apr 21, 2014 at 3:16 AM, Andreas Schwab <sch...@linux-m68k.org>
> wrote:
> > > And if $greo is null the condition will also be true.
> >
> > Really? <runs quick test> I'll be damned.  That explains this problem
> > I've been having.
>
> Yes.  `test' operates based on the number of arguments it receives.  If you
> don't quote `$greo' and it expands to nothing, test receives a single
> argument (-n), tests it for nullness, and returns success.
>
> Chet
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, ITS, CWRU    c...@case.edu
> http://cnswww.cns.cwru.edu/~chet/
>
>

Reply via email to