... could use this in bin/M2 instead ...

# This file is called M2.  Don't make a link to this file.  Instead, make a
# symbolic link named M2 to bin/linkexec, in the Macaulay 2 package.  The job
# of linkexec is basically to run the program in the same directory as
# linkexec whose name is the same as the basename of the symbolic link.

# The advantage of this approach: the Macaulay 2 files become completely
# relocatable; move them anywhere and they still work.  This disadvantage:
# the intuitive approach of making a link to M2 will not work.


M2="$0"
M2BIN=`dirname "$M2"`
M2HOME="$M2BIN/.."
EXE="$M2HOME/libexec/Macaulay2"
if [ ! -f "$EXE" ]
then while ls -l "$M2" | fgrep ' -> ' > /dev/null
     do M2=`ls -l "$M2" | sed 's/.* -> //'`
        echo M2=$M2
     done
     M2BIN=`dirname "$M2"`
     M2HOME="$M2BIN/.."
     EXE="$M2HOME/libexec/Macaulay2"
     if [ ! -f "$EXE" ]
     then exec >&2
	  cat <<EOF
Failed to find the file "$EXE".  See the comments in
$M2 for help.
EOF
	  exit 1
     fi
fi

# The code above is just trying to use 'ls' to follow the chain of symbolic links

export M2HOME
