Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interp: support pwd flags like -P #724

Closed
amancevice opened this issue Sep 6, 2021 · 2 comments · Fixed by #728
Closed

interp: support pwd flags like -P #724

amancevice opened this issue Sep 6, 2021 · 2 comments · Fixed by #728

Comments

@amancevice
Copy link
Contributor

amancevice commented Sep 6, 2021

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
@mvdan
Copy link
Owner

mvdan commented Sep 7, 2021

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.

@mvdan mvdan changed the title Unexpected output of pwd -P interp: support pwd flags like -P Sep 7, 2021
@amancevice
Copy link
Contributor Author

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

mvdan pushed a commit that referenced this issue Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants