On Thu, 2008-02-28 at 20:19 -0600, Mike Hicks wrote:
> EXEC_DIR="$(builtin cd "${0%/*}" && builtin echo "$PWD")"
The only problem I've found so far is with a directory with a '-' as the
first character. 'cd -' changes to $OLDPWD. 'cd -P' and 'cd -L' handle
following symlinks in different ways (I believe 'cd -P' is the default).
But, in order to even execute when the first character in $0 will be a
dash, you have to start the script with an extra '--', as in:
#!/bin/bash --
If you want to check for this, then I'd suggest:
EXEC_DIR="$(builtin cd -P -- "${0%/*}" && builtin echo "$PWD")"
Similarly, you *might* have to pass '-E' to echo to disable some escape
sequence handling, but I'm not quite sure if that's necessary. Bash's
builtin echo won't ignore '--', but we don't need to worry about
accidentally passing a parameter to echo since the first character in
$PWD is always going to be a slash.
I think...
--
Mike Hicks <hick0088 at tc.umn.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20080228/c818a5e4/attachment.pgp