mkropat / sh-realpath

A portable, pure shell implementation of realpath
MIT License
91 stars 17 forks source link

unusual zero args behaviour #10

Open XSven opened 5 years ago

XSven commented 5 years ago

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 commented 5 years ago

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.