Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Absolute path of a path



[moving to -workers]

On 2010-10-28 12:44:51 +0200, Vincent Lefevre wrote:
FYI:

ypig:~> realpath symlink/../vlefevre/symlink
/home/vlefevre

ypig:~> echo symlink/../vlefevre/symlink(:A)
/home/vlefevre/vlefevre/symlink

where symlink is a symbolic link to ".".

I think that this is even a bug in zsh, as

ypig:~> echo symlink/../vlefevre/symlink2(:A)
zsh: no match

So, it seems that resolution as been done correctly (it is detected that symlink/../vlefevre/symlink exists but not symlink/../vlefevre/symlink2), however the output for the former one /home/vlefevre/vlefevre/symlink doesn't exist (there's no vlefevre file or directory in /home/vlefevre).


FWIW, my Perl-based workaround does the right thing, as does the attached simple C program. Seems like a bug.

$ echo $ZSH_VERSION $ZSH_PATCHLEVEL
4.3.10-dev-1 1.5015
$ pwd
/home/bhaskell/tmp
$ readlink symlink
.

$ echo symlink/../tmp/symlink(:A)
/home/bhaskell/tmp/tmp/symlink
## /home/bhaskell/tmp/tmp doesn't exist

$ A () { reply=("$(perl -MCwd=realpath -we 'print realpath shift' $REPLY)") }
$ echo symlink/../tmp/symlink(+A)
/home/bhaskell/tmp

$ gcc -Wall -o realpath-test{,.c}
$ ./realpath-test symlink/../tmp/symlink
/home/bhaskell/tmp

--
Best,
Ben
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) {
	char resolved[PATH_MAX];
	if (argc < 2) {
		fprintf(stderr, "Usage: %s path\n", argv[0]);
		return 1;
	}
	realpath(argv[1], resolved);
	printf("%s\n", resolved);
	return 0;
}


Messages sorted by: Reverse Date, Date, Thread, Author