#!/bin/bash
#set -e

FILE=$1
# get the absolute path of the directory
SELF_PATH=$(cd -P -- "$(dirname -- "$FILE")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$FILE")
# resolve symlinks
while [ -h $SELF_PATH ]; do
	# 1) cd to directory of the symlink
	# 2) cd to the directory of where the symlink points
        # 3) get the pwd
	# 4) append the basename
    DIR=$(dirname -- "$SELF_PATH")
    SYM=$(readlink $SELF_PATH)
    SELF_PATH=$(cd $DIR && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
done
echo $SELF_PATH
