if you try the unit test I send in coreutils patch-proposal you will see all
expected results in variable "expected". these are the results I expect from
realpath.
new content of "coreutils/tests/misc/realpath.sh" is :
...
# when call "realpath . $(pwd)", the two results should be equals what ever
# additional options.
rm -fr "${PWD}/one_link" "${PWD}/one_directory"
mkdir -pv "${PWD}/one_directory"
ln -sv "${PWD}/one_directory" "${PWD}/one_link"
actual="
$(
for wd in "${PWD}/one_directory" "${PWD}/one_link" ; do
for opt in "" -s -m -sm ; do
echo ""
cmd="cd '${wd}' ; realpath ${opt} '${wd}' . a a/b 2>&1"
echo "${cmd}"
LANG=C bash -c "${cmd}"
done
done
)
"
expected="
cd '${PWD}/one_directory' ; realpath '${PWD}/one_directory' . a a/b 2>&1
${PWD}/one_directory
${PWD}/one_directory
${PWD}/one_directory/a
realpath: a/b: No such file or directory
cd '${PWD}/one_directory' ; realpath -s '${PWD}/one_directory' . a a/b 2>&1
${PWD}/one_directory
${PWD}/one_directory
${PWD}/one_directory/a
${PWD}/one_directory/a/b
cd '${PWD}/one_directory' ; realpath -m '${PWD}/one_directory' . a a/b 2>&1
${PWD}/one_directory
${PWD}/one_directory
${PWD}/one_directory/a
${PWD}/one_directory/a/b
cd '${PWD}/one_directory' ; realpath -sm '${PWD}/one_directory' . a a/b 2>&1
${PWD}/one_directory
${PWD}/one_directory
${PWD}/one_directory/a
${PWD}/one_directory/a/b
cd '${PWD}/one_link' ; realpath '${PWD}/one_link' . a a/b 2>&1
${PWD}/one_directory
${PWD}/one_directory
${PWD}/one_directory/a
realpath: a/b: No such file or directory
cd '${PWD}/one_link' ; realpath -s '${PWD}/one_link' . a a/b 2>&1
${PWD}/one_link
${PWD}/one_link
${PWD}/one_link/a
${PWD}/one_link/a/b
cd '${PWD}/one_link' ; realpath -m '${PWD}/one_link' . a a/b 2>&1
${PWD}/one_directory
${PWD}/one_directory
${PWD}/one_directory/a
${PWD}/one_directory/a/b
cd '${PWD}/one_link' ; realpath -sm '${PWD}/one_link' . a a/b 2>&1
${PWD}/one_link
${PWD}/one_link
${PWD}/one_link/a
${PWD}/one_link/a/b
"
#echo "${actual}"
diff <(echo "${actual}") <(echo "${expected}") -C 2 || {
fail=1
sdiff <(echo "${actual}") <(echo "${expected}") --width=150
}
...
in fact, I did the unit test befor the fix.
if you start this test witout applying the fix, "sdiff" will show you
the bug.
for me, when this test fails, the bug becom obvious. no opinion remains.
Patrick
On 02/11/2025 15:30, Bruno Haible wrote:
Patrick GARCIA wrote:
I am just saying that calling "realpath" on "." or on "$PWD" should always
have the same result. I face a case where it si not true. can you see it is
a bug ?
With your example setup, I get:
$ mkdir -p /tmp/phisical_dir
$ ln -sf phisical_dir /tmp/logical_dir
$ cd -L /tmp/logical_dir
$ realpath -L .
/tmp/phisical_dir
$ realpath -L $PWD
/tmp/phisical_dir
$ realpath -L -s .
/tmp/phisical_dir
$ realpath -L -s $PWD
/tmp/logical_dir
I understand you have a preference for the result '/tmp/logical_dir'.
One of the 4 shown realpath invocations, with appropriate options
and argument, shows that result.
Which of the three other shown realpath should, in your opinion,
have the result '/tmp/logical_dir' instead of '/tmp/phisical_dir'?
And why?
Once you have explained that, Pádraig (who wrote the realpath program
in the first place) can judge whether he thinks it is a bug or not.
Bruno