|# A simple test script to demonstrate how to find the|
|# "absolute path" at which a script is running. Used|
|# to avoid some of the pitfals of using 'pwd' or hard-|
|# coded paths when running scripts from cron or another|
|# Try it out:|
|# run the script from the current directory, then|
|# cd.. and run it again (using the file path).|
|# You can see that CURDIR changes depending on where|
|# you run the script from, but ABSDIR stays the same.|
|ABSPATH=$(readlink -f $0)|
|echo "CURDIR is $CURDIR"|
|echo "BASEDIR is $BASEDIR"|
|echo "ABSPATH is $ABSPATH"|
|echo "ABSDIR is $ABSDIR"|
Never leave var refs unquoted unless it's absolutely necessary.
For completeness: Bash implicitly double-quotes var assignments unless there's a space, so those don't need it (there wasn't any here), but var refs (and process substitutions) inside process substitutions (and var refs) need to be double-quoted, unless otherwise absolutely necessary.