Mike Frysinger wrote:
On Thursday 12 February 2009 04:58:09 Andreas Schwab wrote:
Mike Frysinger <vap...@gentoo.org> writes:
On Wednesday 11 February 2009 23:38:10 Rolf Brudeseth wrote:
I would like to propose a new command for bash:
ca [path]
It returns the canonical path based on the current working
directory and
entered path.
If the current working directory has been traversed through a symbolic
link, then listing a higher level path using dotdot's do not always
show
I am looking for. Below is a trivial example:
what's wrong with:
ca() { cd "$(readlink -f -- "$@")"; }
It doesn't work. See below.
ca() { (cd "$@" && pwd -P); }
Yes, that does the trick:
ro...@otto:~/test/B/BB$ ca() { (cd "$@" && pwd -P); }
ro...@otto:~/test/B/BB$ ca ..
/home/rolfb/test/B
~/test/B/BB$ ca ..|xargs ls -l
total 0
-rw-r--r-- 1 rolfb rolfb 0 2009-02-05 23:59 b
lrwxrwxrwx 1 rolfb rolfb 7 2009-02-06 00:09 BB -> ../A/AA
yes, that would be correct ... i thought he wanted to change to the
canonical path, not look it up
-mike
Even if I wanted to change the path, it does not take me to '~/test/B':
ro...@otto:~/test/B/BB$ ca() { cd "$(readlink -f -- "$@")"; }
ro...@otto:~/test/B/BB$ ca ..
ro...@otto:~/test/A$
ro...@otto:~/test/B/BB$ readlink -f ..
/home/rolfb/test/A
ro...@otto:~/test/B/BB$
I get exposed to this on a multitude of systems both at my place of
employment as well as at my ISP, so I thought this would be seen often
enough to where a separate command would be appropriate. Or maybe it
belongs with coreutils instead?
If nothing else, it gave me an excuse to delve into the inner workings
of bash.
Rolf