confluence icon indicating copy to clipboard operation
confluence copied to clipboard

readlink -f doens't work on macOS

Open foolip opened this issue 6 years ago • 2 comments

Like https://github.com/mdittmer/web-apis/issues/41 but for this repo

foolip avatar Jan 21 '19 20:01 foolip

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

mdittmer avatar Jan 22 '19 17:01 mdittmer

Thanks @mdittmer, I'll use that until I feel inspired to send a PR removing the dependency.

foolip avatar Feb 07 '19 10:02 foolip