bug-bash
[Top][All Lists]
Advanced

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

Re: [PATCH] Ensure the command found in the hash table exists, not only


From: Chet Ramey
Subject: Re: [PATCH] Ensure the command found in the hash table exists, not only on POSIXLY_CORRECT
Date: Thu, 07 Jan 2010 16:45:40 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0

On 1/7/10 8:39 AM, Giuseppe Scrivano wrote:
> Hello,
> 
> what do you think about make this the default behavior, not only when
> POSIXLY_CORRECT is specified?  A `stat' is very fast, the cost of a
> stat+fork+exec is almost the same of a fork+exec.

If you want to make this your default behavior, enable the `checkhash'
option with shopt.


> I have a question: how bash should behave in the case you have:
> 
> -------------------------------------------
> export PATH=a:b:$PATH
> 
> mkdir a b
> 
> cat > b/prog.sh << EOF
> echo b/prog.sh
> EOF
> 
> chmod +x b/prog.sh
> 
> prog.sh
> 
> cat > a/prog.sh << EOF
> echo a/prog.sh
> EOF
> 
> chmod +x a/prog.sh
> 
> prog.sh
> -------------------------------------------
> 
> 
> Which prog.sh should be used in this case?  a/prog.sh or b/prog.sh?  The
> former has a higher precedence in PATH but the latter is the hashed
> value.

The hashed value should be preferred as long as it exists.  If you're
concerned about this being a problem, run `hash prog.sh' after creating
it.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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