Re: Is there a special variable for the directory where the script is in
From:
Greg Wooledge
Subject:
Re: Is there a special variable for the directory where the script is in?
Date:
Fri, 12 Feb 2010 08:11:33 -0500
User-agent:
Mutt/1.4.2.3i
On Fri, Feb 12, 2010 at 11:56:49AM +0100, Guillaume Outters wrote:
>
> I usually begin all my scripts with this beast:
>
> absolutiseScripts() { SCRIPTS="$1" ; echo "$SCRIPTS" | grep -q ^/ ||
> SCRIPTS="`dirname "$2"`/$SCRIPTS" ; } ; absolutiseScripts "`command -v "$0"`"
> "`pwd`/." ; while [ -h "$SCRIPTS" ] ; do absolutiseScripts "`readlink
> "$SCRIPTS"`" "$SCRIPTS" ; done ; SCRIPTS="`dirname "$SCRIPTS"`"
>
> I use it with bash on Mac OS X, FreeBSD, Linux, and it seems (just tested now
> at work) that HP/UX 11 with its bare sh can handle it.
Except that HP-UX 10.20 and HP-UX 11.11 don't have readlink(1).
(Maybe it's added in 11.2x? I don't know.)