Skip to content

interp: support pwd flags like -P #724

Description

@amancevice

I use this repo indirectly through go-task and noticed an unexpected result when executing the command pwd -P. The issue is outlined in go-task#533.

In essence, when executed from a symlinked directory, pwd -P outputs the symlink and not the actual physical location on disk.

Example:

mkdir real-dir
ln -s real-dir link-dir
cd link-dir
pwd -P
# => Expected: /path/to/real-dir
# => Actual: /path/to/link-dir

Activity

  1. mvdan commented on Sep 7, 2021

    @mvdan
    Owner

    Ah, that's sort-of-expected given that we don't support any pwd flags right now. See:

    sh/interp/builtin.go

    Lines 186 to 187 in ec61336

    case "pwd":
    r.outf("%s\n", r.envGet("PWD"))

    I think it should be doable with https://pkg.go.dev/path/filepath#EvalSymlinks and a couple of tests, if you're up for sending a PR.

  2. changed the title [-]Unexpected output of `pwd -P`[/-] [+]interp: support pwd flags like -P[/+] on Sep 7, 2021
  3. amancevice commented on Sep 7, 2021

    @amancevice
    ContributorAuthor

    I'm a Go-newbie but I can give it the old college try in the coming days. Thanks!

  4. added a commit that references this issue on Sep 10, 2021
    887152f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions