adus icon indicating copy to clipboard operation
adus copied to clipboard

CWD variable incorrect on OS X

Open isaacl opened this issue 10 years ago • 4 comments

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?

isaacl avatar Nov 14 '15 23:11 isaacl

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

dorneanu avatar Nov 17 '15 12:11 dorneanu

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]}")

isaacl avatar Nov 17 '15 23:11 isaacl

Could you please elaborate more on your testing scenario? I'll try to test it as well..

dorneanu avatar Nov 18 '15 12:11 dorneanu

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.

isaacl avatar Nov 18 '15 15:11 isaacl