bug-bash
[Top][All Lists]
Advanced

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

Re: Create an alias on the fly?


From: Greg Wooledge
Subject: Re: Create an alias on the fly?
Date: Mon, 30 Mar 2020 08:51:05 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Mon, Mar 30, 2020 at 04:24:07AM -0400, Jeffrey Walton wrote:
> I'm testing some software from Master. My testing machines sometimes
> lack the distro tools like makeinfo. It results in things like this:
> 
>     ./bootstrap: 255: makeinfo: not found
>     ./bootstrap: Error: 'makeinfo' not found
> 
> I tried the MAKEINFO=true tricks but they did not work.

Where is "makeinfo" defined?  You haven't shown any bash code yet.

> How can I create an alias on the fly using code like this in Bash?
> 
>     if ! ./bootstrap;
>     then
>         echo "Failed to bootstrap Wget2"
>         exit 1
>     fi
> 
> Thanks in advance.

Um... this code does not define a function (or alias) named "./boostrap".
And in any case, "./bootstrap" appeared to work just fine -- it was
"makeinfo" that was missing.

Also, are you writing a *script*, or are you in an interactive shell?
Aliases do not work in scripts (unless you run bash as sh, or turn on
POSIX mode, or use the shopt to enable aliases in scripts).

If you want to create a *function* on the fly, named "makeinfo", or
named "./bootstrap", you can do that.  In scripts, or in interactive
shells.

It would really be best if you could remove any knowledge of "aliases"
from your brain, because they just get in the way and don't work the way
you expect.

function ./bootstrap {
    printf './bootstrap invoked, with arguments %s\n' "$*"
}

Is that what you want?  To create a function that suppresses the
invocation of "./bootstrap"?  Voila.  Either place that inside the
script where you want to stop the real ./bootstrap from being called,
or export it through the environment, assuming bash is in use in the
required places.



reply via email to

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