[ale] A bash question
Ed Cashin
ecashin at noserose.net
Thu Sep 17 08:32:37 EDT 2009
On Wed, Sep 16, 2009 at 8:49 PM, Michael B. Trausch <mbt at zest.trausch.us> wrote:
> On Wed, 2009-09-16 at 18:06 -0400, Chuck Payne wrote:
>> I am looking for best practise. Thanks.
>
> Rely on $PATH. Seriously.
Yes, in this case I agree that the $PATH is the thing to use.
If it was a different situation, like looking for /etc/lvm.conf or
/etc/lvm/lvm.conf, I'd probably do,
conf=/etc/lvm.conf
test -r "$conf" || conf="/etc/lvm/lvm.conf"
... to get the functional equivalent of your code. I like it that
each filename only appears once. If you have more than two
filenames a loop can be nice.
dirs="/etc /etc/lvm /opt/lvm-X.Y.Z/etc /mnt/foo/etc"
conf=
for d in $dirs; do
if test -r "$d"; then
conf="$d/lvm.conf"
break
fi
done
if test ! "$conf"; then
exec 1>&2
echo 'oh noes!'
exit 1
fi
rm -f "$conf" # (just kidding)
--
Ed Cashin <ecashin at noserose.net>
http://noserose.net/e/
More information about the Ale
mailing list