head	1.2;
access;
symbols
	VER_0_3:1.2
	VER_0_2:1.1;
locks; strict;
comment	@# @;


1.2
date	95.03.24.11.43.35;	author coulter;	state Exp;
branches;
next	1.1;

1.1
date	95.02.18.08.36.38;	author coulter;	state Exp;
branches;
next	;


desc
@return a path to the ultimate destination of a link
@


1.2
log
@Checkin version for 0.3 distribution.
@
text
@#! /bin/ksh
USAGE='USAGE: follow_link FILE_PATH
   If FILE_PATH is not a link, echo path, else, echo a path (relative or
   absolute) to the ultimate destination of the link).
'
# (C) Copyright 1995 by Michael Coulter.  All rights reserved.

# Process parameters

   if [ $# -ne 1 ]
   then
      echo "$USAGE" >&2
      exit 1
   fi
   FILE_PATH="$1"; shift

# Do it

   if [ ! -L "$FILE_PATH" ]
   then
      echo "$FILE_PATH"
      exit 0
   fi
   LINK="$FILE_PATH"
   while [ -L "$LINK" ]
   do
      NEW_LINK="$(ls -l "$LINK" | cut -c56-500 | sed -e 's/^.* //')"
      if [ "$NEW_LINK" = "${NEW_LINK#/}" ]
      then
	 # NEW_LINK is relative, add dirname of FILE_PATH
	 DIR_PATH="$(dirname "$LINK")"
	 NEW_LINK="$DIR_PATH/${NEW_LINK}"
      fi
      LINK="$NEW_LINK"
   done
   echo "$LINK"
@


1.1
log
@Checkpoint version before fixing /usr/bin install
@
text
@d6 1
@
