On Tue, Aug 9, 2011 at 2:51 PM, Bob Proulx <b...@proulx.com> wrote: > Jon Seymour wrote: >> readlink_f() >> { >> local path="$1" >> test -z "$path" && echo "usage: readlink_f path" 1>&2 && exit 1; > > An extra ';' there that doesn't hurt but isn't needed. > >> local dir >> >> if test -L "$path" >> then >> local link=$(ls -l "$path" | sed "s/.*-> //") > > I would be inclined to also look for a space before the " -> " too. > Because it just is slightly more paranoid. > > local link=$(ls -l "$path" | sed "s/.* -> //") > >> if test "$link" = "${link#/}" >> then >> # relative link >> dir="$(dirname "$path")" > > As an aside you don't need to quote assignments. They exist inside > the shell and no word splitting will occur. It is okay to assign > without quotes here and I think it reads slightly better without. > > dir=$(dirname "$path") > >> readlink_f "${dir%/}/$link" >> else >> # absolute link >> readlink_f "$link" >> fi >> elif test -d "$path" >> then >> (cd "$path"; pwd -P) # normalize it >> else >> dir="$(cd $(dirname "$path"); pwd -P)" >> base="$(basename "$path")" > > Same comment here about over-quoting. If nothing else it means that > syntax highlighting is different. > > dir=$(cd $(dirname "$path"); pwd -P) > base=$(basename "$path") > >> echo "${dir%/}/${base}" >> fi >> } > > And of course those are just suggestions and nothing more. Feel free > to ignore.
Tips appreciated, thanks. jon.