absolute=$(cd "$relative" && pwd)
Conversely, if you’re writing a bash script and it needs to be robust against people who do export CDPATH, you can do it like this instead: absolute=$(CDPATH=. cd "$relative") absolute=$(cd "$relative" && pwd)
Conversely, if you’re writing a bash script and it needs to be robust against people who do export CDPATH, you can do it like this instead: absolute=$(CDPATH=. cd "$relative")A bit of scripting is then wanted to coerce the output of 'dirs' into a readable format.
alias cdp='cd ~/src/photostructure'
for example. I found I only really needed < 10 directories aliases in this fashion. d () { dirs -p | nl -v 0; }
The numbers in the left-hand column correspond to offsets from top-of-stack. So, if you see $ d
0 ~
1 /var/log/apt
to switch back to /var/log/apt, you could type:
$ pushd +1https://www.freebsd.org/cgi/man.cgi?query=readlink&sektion=1
So how is that a Linux-centric view again?
> if the -f option is specified, the output is canonicalized by following every symlink in every component of the given path recursively. readlink will resolve both absolute and relative paths, and return the absolute pathname corresponding to file. In this case, the argument does not need to be a symbolic link.
This is the case for *BSD, GNU/Linux, and Irix. If macOS would prioritize being consistent with the other Nix OSs, it would be supported too, but alas Apple doesn’t.
> if the -f option is specified, the output is canonicalized by following every symlink in every component of the given path recursively. readlink will resolve both absolute and relative paths, and return the absolute pathname corresponding to file. In this case, the argument does not need to be a symbolic link.
[0] https://www.freebsd.org/cgi/man.cgi?query=readlink&sektion=1
Update:
And here’s the OpenBSD man page from 1997 refuting your claim it’s for formatting as well:
https://man.openbsd.org/OpenBSD-2.2/readlink.1
Update 2:
OpenBSD (1997): http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/readlink/r...
GNU/Linux (2003): https://lists.gnu.org/archive/html/bug-gnu-utils/2003-02/msg...
So it definitely did exist in at least one *BSD before Linux.