confluence
confluence copied to clipboard
readlink -f doens't work on macOS
Like https://github.com/mdittmer/web-apis/issues/41 but for this repo
I coped with this using the following bandaid (not saying it's best long term, but it has served me well):
/first/dir/in/your/PATH/readlink
#!/bin/sh
# In the special case of "readlink --canonicalize [filename] [...]", simulate
# GNU's readlink behaviour.
if [ "$1" != "--canonicalize" ] && [ "$1" != "-f" ]; then
/usr/bin/readlink $*
exit $?
fi
TARGET_FILE=$2
cd `dirname $TARGET_FILE`
TARGET_FILE=`basename $TARGET_FILE`
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE=`readlink $TARGET_FILE`
cd `dirname $TARGET_FILE`
TARGET_FILE=`basename $TARGET_FILE`
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR=`pwd -P`
RESULT=$PHYS_DIR/$TARGET_FILE
echo $RESULT
exit 0
Thanks @mdittmer, I'll use that until I feel inspired to send a PR removing the dependency.