adus
adus copied to clipboard
CWD variable incorrect on OS X
from readlink man page: If the given argument is not a symbolic link, readlink will print nothing and exit with an error.
The end result is CWD is set to working directory not script location, and tools can not be found. Bash is fun isn't it?
Unfortunately I don't have any Mac to test that. @koko-ng changed that line in last commit: https://github.com/dorneanu/adus/commit/6d157c9f7a9140c1d818e8aad468dc9f44e509ca
That commit is just broken: even posix readlink only has output for symlinks. But I think this will work for both posix and os x:
$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")
Could you please elaborate more on your testing scenario? I'll try to test it as well..
Sure. ${BASH_SOURCE[0]} is known to documented as the path to script, so I didn't test this.
I have posix version of utilities on OS X alongside standard via brew install coreutils. I tested the output of echo "$(readlink "$PTH" || echo "$PTH")" for each readlink version where $PTH was:
- path to symlink
- nonexistant path
- path to standard file
in addition, both man pages say readlink without options resolves a symlink if passed one, and returns non-zero error code w/o output if input isn't a symlink.