Nemo's bash challenge for the day

Michael Still mikal at stillhq.com
Sat Mar 30 08:35:35 EST 2002


On Fri, 29 Mar 2002, Nemo - earth native wrote:

> #!/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)

#!/bin/bash

# Find the destination of a link in only shell
# $1 is the name of the file to check (including path if required)

ls -l $1 | tr -s " " | sed 's/^.*[0-9] //' | sed 's/^.*-> //'

(This can probably be optimized more, as this is going to invoke a quite
silly number of proceses -- 4 in this case... Also why do you care about
symlinks? If you just use them, then you'll end up in the right place
anyway).

Mikal

-- 

Michael Still (mikal at stillhq.com)     UMT+11hrs





More information about the linux mailing list