#!/bin/sh ####################################### ## Hand in a symlink, get back its (end) target ## Usage: lnptr FILE [FILE...] ## lnptr 0.1, Copyright (c) 2003 by Adam Katz , GPL ####################################### # ensure we have a string and it is a file or directory [ -z "$1" ] && exit 0 [ -f "$1" ] || [ -d "$1" ] || if echo $1 |grep '^-' >/dev/null then grep '^## ' `which $0 2>/dev/null || echo $0` |sed 's/^...//' && exit 0 else echo "`echo $0|sed 's:.*/::g'`: $1: No such file or directory" && exit 1 fi # (solaris 5.9's /bin/sh doesn't like `[ -e filename ]') pointer="$1" while true; do this="$pointer" pointer=`ls -l "$this" |awk '{print $11}'` # link target (empty if not a link) [ -z "$pointer" ] && break # if not a link, we're done if echo "$pointer" |grep -v '^/' >/dev/null; then pdir=`dirname "$this"` pointer="$pdir/$pointer" # make absolute fi done cd `dirname "$this"` # get rid of ../.. etc w/out sed echo "`pwd`/`echo $this |sed 's:^.*/::g'`" # the answer! [ -n "$2" ] && shift && "$0" "$@" # call this on remaining arguments