Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!usc!ucsd!ucbvax!MCIRPS2.MED.NYU.EDU!karron From: karron@MCIRPS2.MED.NYU.EDU Newsgroups: comp.sys.sgi Subject: Symbolic Links for Lunks (Re-Thunk) Message-ID: <9008092147.AA00181@mcirps2.med.nyu.edu> Date: 9 Aug 90 19:45:26 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: karron%CMCL2.NYU.EDU@cunyvm.cuny.edu Organization: The Internet Lines: 145 X-Unparsable-Date: Thu, 9 Aug 90 14:47:48 DSD There was a problem with creating links from outside your current working directory that I think I fixed in this version of the script, and a bug in file existance testing ( [ -x ] for [ -f ] ) that would not let you link to a nonexecutable file. I think that this works. While not the most artful shell script, This is what I use to protect myself from some of the problems with symbolic links. It has been pointed out to me that ln -si will prevent you from clobbering a file with a link too. Then my only improvement is that this script checks for existance of files to link to and qualifies file paths relative to root so that you can't get a dangling link (a linkage to a file that does not exist because it is being evaluated relative to some arbitrary current working location). Thanks for all your input, and I hope that this works better. ---------cut here-------------------------------------------------------------- #! /bin/sh # more user frendly front end for ln -s # prevents you from making linkages the wrong way and clobbering what # you want to LINK to. # # fully qualifies FILE and LINK names so you # don't get dangling linkages. clear #. Version.mac FILE="$1" if echo $FILE | egrep -s "^/" then echo "File name is fully qualified" else echo "File name being qualified" FILE_DIR_NAME=`dirname $FILE` FILE="`(cd $FILE_DIR_NAME;pwd)`/`basename $FILE`" fi echo "Enter existing file you wish create a link to" if [ "$1" ] then echo "or enter a return to use $FILE" fi read FILE if [ -z "$FILE" ] then FILE=$1 fi if echo $FILE | egrep -s "^/" then echo "File name is fully qualified" else echo "File name being qualified" FILE_DIR_NAME=`dirname $FILE` FILE="`(cd $FILE_DIR_NAME;pwd)`/`basename $FILE`" fi if [ -f $FILE ] then echo "GOOD. $FILE exists" ls -ld $FILE else echo "$FILE does not exist" echo " How do you expect me to make a link to a file I can't find." exit 1 fi echo "\n\n" LINK="$2" if echo $LINK | egrep -s "^/" then echo "Link name is fully qualified" else echo "Link name being qualified" LINK_DIR_NAME=`dirname $LINK` LINK="`(cd $LINK_DIR_NAME;pwd)`/`basename $LINK`" fi echo "Enter name of link to create $LINK" if [ -z "$2" ] then echo "or return to use `basename $FILE`" fi read LINK if [ -z "$LINK" ] then LINK=$2 fi if echo $LINK | egrep -s "^/" then echo "Link name is fully qualified" else echo "Link name being qualified" LINK_DIR_NAME=`dirname $LINK` LINK="`(cd $LINK_DIR_NAME;pwd)`/`basename $LINK`" fi if [ -z "$LINK" ] then LINK=`basename $FILE` echo "do you want me to use $LINK as your local LINK to \n$FILE ?" echo "\nReturn to continue,anything else aborts." read ans if [ -n "$ans" ] then exit 1 fi fi if [ -f $LINK ] then echo "bad bad bad boy, $LINK exists. If you don't believe me, look" ls -ld $LINK exit 1 else echo "nice kitty" echo " $LINK is ready to create" fi ln -s $FILE $LINK echo "\n\n" ls -ld $FILE $LINK | cut -c1-10,40- echo "$0 : Completed" # . End.mac exit 0 +-----------------------------------------------------------------------------+ | karron@nyu.edu Dan Karron | | . . . . . . . . . . . . . . New York University Medical Center | | 560 First Avenue \ \ Pager <1> (212) 397 9330 | | New York, New York 10016 \**\ <2> 10896 <3> | | (212) 340 5210 \**\__________________________________________ | +-----------------------------------------------------------------------------+