bug-bash
[Top][All Lists]
Advanced

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

Re: [POSIX conformance] "." looks for file in the current directory


From: Stephane Chazelas
Subject: Re: [POSIX conformance] "." looks for file in the current directory
Date: Tue, 10 Jun 2008 13:40:28 +0100
User-agent: Mutt/1.5.16 (2007-09-19)

On Tue, Jun 10, 2008 at 06:21:13AM -0600, Eric Blake wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> According to Andreas Schwab on 6/10/2008 3:20 AM:
> | Stephane_Chazelas@yahoo.fr writes:
> |
> |> SUSv3> Some older implementations searched the current directory
> |> SUSv3> for the file, even if the value of PATH disallowed it.
>
> Yes, bash has a bug here, to the point that even Autoconf documents bash's
> bug:
> http://www.gnu.org/software/autoconf/manual/html_node/Limitations-of-Builtins.html#Limitations-of-Builtins
[...]

Actually, the manual says:

       source filename [arguments]
              Read  and execute commands from filename in the
              current shell environment and return the exit
              status of the last command executed from filename.
              If filename does not contain a slash, file names
              in PATH are used to find the directory containing
              filename.  The file searched for in PATH need not
              be executable.  When  bash  is not  in  posix
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              mode, the current directory is searched if no file
              ~~~~
              is found in PATH.  If the sourcepath option to the
              shopt builtin command is turned off, the PATH is
              not searched.  If any arguments are supplied, they
              become the positional parameters when  filename
              is  executed.   Otherwise  the  positional
              parameters  are unchanged.   The  return  status
              is the status of the last command exited within
              the script (0 if no commands are executed), and
              false if filename is not found or cannot be read.


So it is indeed a bug.

The code has:

  /* Things that should be turned on when posix mode is disabled. */
  if (on == 0)
    {
      source_searches_cwd = 1;
      expand_aliases = interactive_shell;
    }

But the problem is that the default value is 1 as well:

/* If non-zero, `.' looks in the current directory if the filename argument
   is not found in the $PATH. */
int source_searches_cwd = 1;


So the fix should just be to change the 1 to 0 above.

-- 
Stéphane




reply via email to

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