On Thu, Aug 18, 2011 at 9:02 PM, Jeroen Demeyer <jdeme...@cage.ugent.be>wrote:
> Hello sage-devel, > > Can somebody explain the rationale for the following lines in > $SAGE_ROOT/sage: > if [ "$SAGE_ROOT" = "....." ]; then > SAGE_ROOT=`readlink -n "$0" 2> /dev/null` || \ > SAGE_ROOT=`realpath "$0" 2> /dev/null` || \ > SAGE_ROOT="$0" > > I think the following would work equally well: > if [ "$SAGE_ROOT" = "....." ]; then > SAGE_ROOT="$0" > > > I assume those lines are supposed to try to determine the location of the sage install when sage is not run from the directory where is it install. I think that they work when the sage executable is called directly, and your proposal would probably work equally well in that case, but they seem broken in other cases. I generally link sage-(release number) to ~/sage, and then I link ~/bin/sage to ~/sage/sage, and I've always had to set SAGE_ROOT explicitly. Are those lines supposed to be there so that I don't have to set the path explicitly? I think that in my case something like the following would work: cd "${0%/*}" SAGE_RELATIVE_PATH=`readlink -n "$0"` cd "${SAGE_RELATIVE_PATH%/}" SAGE_ROOT=`pwd` > Note that this is not needed to get an absolute (rather than relative) > path, since below there is > # Make root absolute: > cd "$SAGE_ROOT" > SAGE_ROOT=`pwd` > > If we really want to resolve symbolic links, we could replace `pwd` by > `pwd -P` (physical path). > > > In any case, "readlink -n" certainly does NOT do what is intended and > should be removed (#11707): > - It only works when `$0` (the sage executable itself) is a symbolic > link, it does not work when some other component in the path is a > symbolic link. > - If the sage executable is a symbolic link, then `readlink -n` returns > the link itself, not the canonicalized name. Example: if > `/usr/local/sage-4.7.1/sage` is a symbolic link to `sagefoo`, then > `SAGE_ROOT` would become `sagefoo` when `'/usr/local/sage-4.7.1/sagefoo` > is intended. > > -- > To post to this group, send an email to sage-devel@googlegroups.com > To unsubscribe from this group, send an email to > sage-devel+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-devel > URL: http://www.sagemath.org > -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org