Sat, 3 Sep 2005 13:27:28 -0400, "Chris F.A. Johnson"
<cfajohnson@gmail.comwrote:
I have never used the [[]] form, because it is not portable.
I needed a bash eqivalent of dirname, to be used for determining the
absolute pathname of the current script. For the "dirname" portion of
the bash code below, I could not think of anything better than using
[[ ]]
If anyone knows a better way
#!/bin/bash
quit () {
echo "${0/}: $*" >&2
exit 5
}
set -e -u
if [[ ${0-} != */* ]]; then
my0dir='.'
elif [[ ${0%/*} == '' ]]; then
my0dir='/'
else
my0dir=${0%/*}
fi
test -n "$my0dir" || quit "my own directory has null value"
test -d $my0dir || quit "my own \"$my0dir\" directory not found"
if ! pushd $my0dir &/dev/null; then
quit "my own \"$my0dir\" directory not accessible"
else
mydirpath=$(pwd)
test -n "$mydirpath" || quit "my own directory \$(pwd) returned null value"
test -d $mydirpath || quit "my own \"$mydirpath\" directory path not found"
popd /dev/null
fi
echo "mydirpath=$mydirpath"