On Tue, Jun 10, 2008 at 3:14 PM, Douglas Royds <[EMAIL PROTECTED]> wrote:
> $ cat /usr/local/bin/which_really
> #!/bin/bash
> candidate=`which $1`
> while [ -L "$candidate" ]; do
>  ls -lh --color $candidate
>  candidate=`ls -lh $candidate | gawk '{print $NF}'`
> done
> ls -lh --color $candidate

Excellent stuff :-) I was just struck by the same thing myself a day
ago, but hadn't bothered solving it.

I replaced "gawk" with "awk", and then by a couple of invocations of
cut ... and then, seeing as you're using GNU ls, I cheated with the
--time-style to replace the whole line with
 candidate=$(ls -lh --time-style + $candidate | cut -d' ' -f9)

On my Ubuntu 6.06 server machine, for vi I get ...
$ ./whichreally vi
lrwxrwxrwx 1 root root 20 Jun 23  2006 /usr/bin/vi -> /etc/alternatives/vi
lrwxrwxrwx 1 root root 12 Sep 12  2007 /etc/alternatives/vi -> /usr/bin/vim
lrwxrwxrwx 1 root root 21 Jun 23  2006 /usr/bin/vim -> /etc/alternatives/vim
lrwxrwxrwx 1 root root 18 Sep 12  2007 /etc/alternatives/vim ->
/usr/bin/vim.basic
-rwxr-xr-x 1 root root 1.1M Aug 28  2007 /usr/bin/vim.basic

-jim

Reply via email to