[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is there a special variable for the directory where the script is in
From: |
Guillaume Outters |
Subject: |
Re: Is there a special variable for the directory where the script is in? |
Date: |
Fri, 12 Feb 2010 11:56:49 +0100 (CET) |
Marc a écrit :
> source $(dirname "$0")/functions.sh
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.
It does a lot of symlink-resolution, because I typically store my scripts in an
src/scripts directory, with symlinks from $HOME/bin/tagadatsointsoin to
$HOME/src/scripts/tagadatsointsoin.
--
Guillaume
- Re: Is there a special variable for the directory where the script is in?,
Guillaume Outters <=