[Top][All Lists]

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

Re: hash not restored after running command -p

From: Oğuz
Subject: Re: hash not restored after running command -p
Date: Sun, 31 Oct 2021 20:36:49 +0300

On Sun, Oct 31, 2021 at 7:07 PM Mike Jonkmans <bashbug@jonkmans.nl> wrote:
> On Sun, Oct 31, 2021 at 05:23:03PM +0200, Oğuz wrote:
> > 31 Ekim 2021 Pazar tarihinde Mike Jonkmans <bashbug@jonkmans.nl> yazdı:
> > >
> > > Using the hash as alias for commands, that are not in your PATH,
> > > seems risky though.
> >
> > Why? Risky how?
> Risky, mostly on a cognitive level.
> 'command -p foo' doesn't look like it has a side effect.

How does a command look like it has side effects?

> E.g. assume you have /usr/local/bin/foo and /bin/foo
>         PATH=/usr/local/bin
>         command -p foo
>         foo
> You would not think that /bin/foo is executed for foo, given the value of 

I suppose I would not, because the manual doesn't say `command -p' has
this effect. I'll give you that.

> It could also lead to bugs.
> E.g.
>         PATH=/usr/local/bin
>         source script
>         foo
> When the 'command -p foo' is introduced in the sourced script, foo changes.

Yes, that's how `source' works; contents of the sourced file alters
the sourcing application's execution environment. In addition to
calling `command -p foo', if the sourced file changes `PATH', or
defines a function named `foo', or enables `expand_aliases' and
defines an alias named `foo', `foo' 'changes'.

> --
> Regards, Mike Jonkmans

reply via email to

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