Nemo's bash challenge for the day

David Price davidmprice at dingoblue.net.au
Fri Mar 29 14:35:41 EST 2002


On Fri, Mar 29, 2002 at 11:31:26AM +1100, Nemo - earth native wrote:
> While we're talking bash scripts... does anyone know an easier way of
> doing this:
> 
> #!/bin/sh
> basename `ls -o $1 | awk -F " "  '{ print $10}'`
> 
> (call it with $1 as a symbolic link, and it returns the name of the file
> it's linked to)
> 
> .../Nemo
> 

I have a /bin/readlink which does some of what you want.  It looks
like it's in package "debianutils", so I'm not sure if it's available
on the majority of systems.  Also, it doesn't do exactly the same, 
since it recursively follows symlinks - but I would guess that would
usually be what is wanted.

basename "`readlink "$1"`"

Alternatively you could reintroduce that Perl dependency that Michael
just helped you remove, and use Perl's readlink.  But I guess that
depends on whether you consider a bash script that make repeated calls
to Perl to still be a bash script :)

David




More information about the linux mailing list