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.
This is the test case I used, I expect to get "hello world" twice: -------------------------------------------- export PATH=a:b:$PATH cd /tmp mkdir a b cat > a/prog.sh << EOF echo hello world EOF chmod +x a/prog.sh cp a/prog.sh b/prog.sh prog.sh rm a/prog.sh prog.sh -------------------------------------------- It works with "POSIXLY_CORRECT=1 bash" and dash handles it too. Without POSIXLY_CORRECT I get: hello world /tmp/failure.sh: line 13: a/prog.sh: No such file or directory 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. Thanks, Giuseppe Scrivano >From c786059d65fc47d6265ebde3fe88c18c381dc77b Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano <gscriv...@gnu.org> Date: Thu, 7 Jan 2010 13:52:13 +0100 Subject: [PATCH] Ensure the command found in the hash table exists, not only on POSIXLY_CORRECT --- findcmd.c | 19 +++++++------------ 1 files changed, 7 insertions(+), 12 deletions(-) diff --git a/findcmd.c b/findcmd.c index 1f05394..b8c4fbe 100644 --- a/findcmd.c +++ b/findcmd.c @@ -301,18 +301,13 @@ search_for_command (pathname) hashed_file = phash_search (pathname); /* If a command found in the hash table no longer exists, we need to - look for it in $PATH. Thank you Posix.2. This forces us to stat - every command found in the hash table. */ - - if (hashed_file && (posixly_correct || check_hashed_filenames)) - { - st = file_status (hashed_file); - if ((st & (FS_EXISTS|FS_EXECABLE)) != (FS_EXISTS|FS_EXECABLE)) - { - phash_remove (pathname); - free (hashed_file); - hashed_file = (char *)NULL; - } + look for it in $PATH. */ + st = file_status (hashed_file); + if ((st & (FS_EXISTS|FS_EXECABLE)) != (FS_EXISTS|FS_EXECABLE)) + { + phash_remove (pathname); + free (hashed_file); + hashed_file = (char *)NULL; } if (hashed_file) -- 1.6.5