script Unix:
dir=$(cd $(dirname "$0"); pwd)
: $0 - + script . (/...) (../, dir/...). , $(dirname "$0") ( ). ; "$ 0" .
Then we will be cdin this directory and pwdwill return the absolute path in which we will end.
Works for kshand bash.
In a C program, you should check argv[0]. I'm not sure if the shell will put the full path there. If you have problems, I suggest wrapping your executable with a small script that prepares the environment, and then calls your executable with:
exec "$dir/"exe "$@"
source
share