help-bash
[Top][All Lists]
Advanced

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

Re: How to override the default executable resolution order of PATH?


From: Alan D. Salewski
Subject: Re: How to override the default executable resolution order of PATH?
Date: Sun, 3 May 2020 07:11:08 -0400
User-agent: Mutt/1.13.2 (2019-12-18)

On 2020-05-03 00:11:12, Andreas Kusalananda Kähäri spake thus:
> On Sat, May 02, 2020 at 04:48:06PM -0500, Peng Yu wrote:
> > Suppose
> > 
> > 1. dir1 is before dir2 in PATH.
> > 2. Most of the executables with the same name should be resolved to
> > those in dir1 instead of dir2.
> > 3. There are a small fraction of executables with the same name should
> > resolve to those in dir2.
> > 4. dir1 and dir2 can not be modified.
> > 
> > Does anybody know the best way to fine control how the executables are
> > resolved to? Thanks.
> > 
> > -- 
> > Regards,
> > Peng
> 
> For the special cases, the commands that should be picked out of dir2
> rather than dir1, create shell functions that override their names:
> 
>       foo () { command dir2/foo "$@"; }
> 
> 
> -- 
> Andreas (Kusalananda) Kähäri
> SciLifeLab, NBIS, ICM
> Uppsala University, Sweden

Another option would be to create a directory that is always first in PATH,
and then create symlinks in that directory to the executables that should
always be first.

    mkdir ~/a1

    PATH=${HOME}/a1:${PATH}

    ln -s -t ~/a1 /path/to/executable

This would have the advantage of working for existing shells that are already
configured with 'a1' to be first in PATH; you could move executables "to the
front of the line", as it were, for those shells (in addition to the current
shell) those by manipulating the symlinks in 'a1'.

In the example above, "a1" means "always first", but the approach can be
scaled up with "a2" (always second), "a3" (always third), etc.

    mkdir ~/a1 ~/a2 ~/a3

    PATH=${HOME}/a1:${HOME}/a2:${HOME}/a3:${PATH}

    ...

-- 
-----------------------------------------------------------------
a l a n   d.   s a l e w s k i                   address@hidden
1024D/FA2C3588 EDFA 195F EDF1 0933 1002  6396 7C92 5CB3 FA2C 3588
-----------------------------------------------------------------


reply via email to

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