git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/5] commit test: Change $PWD to $(pwd)

From
David Kastrup <dak@gnu.org>
Date
May 27, 2014, 07:35 UTC
Message-ID
<87sinv3c8t.fsf@fencepost.gnu.org>
In-Reply-To
<53843206.3040902@viscovery.net>
Johannes Sixt <j.sixt@viscovery.net> writes:
> That said, it is not wrong to use $(pwd) with test_set_editor, it's just
> unnecessarily slow.

Any shell that knows $(...) is pretty sure to have pwd as a built-in. I don't think Git will run on those kind of ancient shells reverting to /bin/pwd here.

The autoconf manual (info "(autoconf) Limitations of Builtins") states
'pwd'
     With modern shells, plain 'pwd' outputs a "logical" directory name,
     some of whose components may be symbolic links.  These directory
     names are in contrast to "physical" directory names, whose
     components are all directories.
     Posix 1003.1-2001 requires that 'pwd' must support the '-L'
     ("logical") and '-P' ("physical") options, with '-L' being the
     default.  However, traditional shells do not support these options,
     and their 'pwd' command has the '-P' behavior.
     Portable scripts should assume neither option is supported, and
     should assume neither behavior is the default.  Also, on many hosts
     '/bin/pwd' is equivalent to 'pwd -P', but Posix does not require
     this behavior and portable scripts should not rely on it.
     Typically it's best to use plain 'pwd'.  On modern hosts this
     outputs logical directory names, which have the following
     advantages:
        * Logical names are what the user specified.
        * Physical names may not be portable from one installation host
          to another due to network file system gymnastics.
        * On modern hosts 'pwd -P' may fail due to lack of permissions
          to some parent directory, but plain 'pwd' cannot fail for this
          reason.
     Also please see the discussion of the 'cd' command.

So $PWD is pretty much guaranteed to be the same as $(pwd) and pretty much guaranteed to _not_ be "unnecessarily slow" when not run in an inner loop.

However, looking at (info "(autoconf) Special Shell Variables") I see
'PWD'
     Posix 1003.1-2001 requires that 'cd' and 'pwd' must update the
     'PWD' environment variable to point to the logical name of the
     current directory, but traditional shells do not support this.
     This can cause confusion if one shell instance maintains 'PWD' but
     a subsidiary and different shell does not know about 'PWD' and
     executes 'cd'; in this case 'PWD' points to the wrong directory.
     Use '`pwd`' rather than '$PWD'.

Ok, probably Git relies on Posix 1003.1-2001 in other respects so it's likely not much of an actual issue.

-- 
David Kastrup
Previous: Johannes SixtNext: Caleb Thompson
Message 13 of 25 in “commit: support commit.verbose and --no-verbose”
  1. commit: support commit.verbose and --no-verboseCaleb Thompson, May 25, 2014
  2. Jeremiah MahlerMay 25, 2014
  3. Jeremiah MahlerMay 25, 2014
  4. Duy NguyenMay 25, 2014
  5. Eric SunshineMay 25, 2014
  6. 0/5 commit: support commit.verbose and --no-verboseCaleb Thompson, May 26, 2014
  7. 1/5 commit test: Use test_config instead of git-configCaleb Thompson, May 26, 2014
  8. 2/5 commit test: Change $PWD to $(pwd)Caleb Thompson, May 26, 2014
  9. Johannes SixtMay 27, 2014
  10. Eric SunshineMay 27, 2014
  11. Jeremiah MahlerMay 27, 2014
  12. Johannes SixtMay 27, 2014
  13. David KastrupMay 27, 2014
  14. 3/5 commit test: Use write_scriptCaleb Thompson, May 26, 2014
  15. Eric SunshineMay 27, 2014
  16. Junio C HamanoMay 27, 2014
  17. 4/5 commit test: test_set_editor in each testCaleb Thompson, May 26, 2014
  18. Eric SunshineMay 27, 2014
  19. 5/5 commit: support commit.verbose and --no-verboseCaleb Thompson, May 26, 2014
  20. Jeremiah MahlerMay 26, 2014
  21. Caleb ThompsonMay 26, 2014
  22. Jeremiah MahlerMay 26, 2014
  23. Jeremiah MahlerMay 26, 2014
  24. Caleb ThompsonMay 26, 2014
  25. Jeremiah MahlerMay 26, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.