#!/bin/bash
#
# __copy1__
# __copy2__
#
CMD=$(basename $0)

usage()
{
	echo "usage: $CMD filename" >&2
	exit 127
}



resolve_link()
{
	local file=$1
	local link=

	[ -L "$file" ] || {
		echo "$file"
		return 0
	}

	link=$(ls -l "$file" | sed -e 's/.* -> //')

	# absolutize path
	#
	dir=$(dirname "$link")
	link=$(basename "$link")

	cd $(dirname "$file")	|| return 1
	cd "$dir"		|| return 1
	dir=$(pwd)

	echo "$dir/$link"
	return 0
}

[ $# != 1 ] && usage

resolve_link "$1"
exit $?
