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

unusual zero args behaviour #10

Open
XSven opened this issue Mar 31, 2019 · 1 comment
Open

unusual zero args behaviour #10

XSven opened this issue Mar 31, 2019 · 1 comment

Comments

@XSven
Copy link

XSven commented Mar 31, 2019

Dear Michael,

I have found this project while searching for a pure perl implementation of realpath. I was curious to see your tests and I have replaced the body of your realpath() function with a call of my system realpath

realpath() {
  /opt/freeware/bin/realpath "$1"
}

My system realpath is part of the rpm package coreutils-8.25-1.ppc. The test it_outputs_pwd_when_passed_zero_args
fails. The system realpath does not like a zero arguments or an empty string argument. You have implemented a kind of fallback or default behaviour. We could argue, if this a good idea, assuming that the behaviour of both realpath implementations should be identical.

What I do not understand is why the default behaviour returns a slash terminated PWD instead of PWD itself. Maybe you could say some words about your motivation. I would have used the variable substitution operator :- instead

realpath() {
  canonicalize_path "$(resolve_symlinks "${1:-.}")"
}

This would run _canonicalize_dir_path() instead of _canonicalize_file_path() and it would return PWD.

Kind regards
Sven

@mkropat
Copy link
Owner

mkropat commented Apr 7, 2019

I was curious to see your tests and I have replaced the body of your realpath() function with a call of my system realpath

I never actually tried that, but I like the idea 👍

What I do not understand is why the default behaviour returns a slash terminated $PWD instead of $PWD itself. Maybe you could say some words about your motivation.

I don't recall the original motivation. However, my guess is that I didn't think about it all that much. I probably just wanted it to do something.

I like the idea of it returning $PWD instead of $PWD/. I'd merge a PR that changes this behavior.

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

No branches or pull requests

2 participants