On Linux, the readlink utility accepts an option -f that follows additional links. This doesn’t seem to work on Mac and possibly BSD based systems. What would the equivalent be?
Here’s some debug information:
$ which readlink; readlink -f
/usr/bin/readlink
readlink: illegal option -f
usage: readlink [-n] [file ...]
readlink -fdoes two things:If you want to, you can just build a shell script that uses vanilla readlink behavior to achieve the same thing. Here’s an example. Obviously you could insert this in your own script where you’d like to call
readlink -fNote that this doesn’t include any error handling. Of particular importance, it doesn’t detect symlink cycles. A simple way to do this would be to count the number of times you go around the loop and fail if you hit an improbably large number, such as 1,000.
EDITED to use
pwd -Pinstead of$PWD.Note that this script expects to be called like
./script_name filename, no-f, change$1to$2if you want to be able to use with-f filenamelike GNU readlink.