"sage -sh" question and possible patch

53 views
Skip to first unread message

Mariah Lenox

unread,
Sep 25, 2009, 4:04:37 PM9/25/09
to sage-...@googlegroups.com
The open trac tickets #4644 and #5507 discuss
problems with "sage -sh", specifically

#4644 - No new prompt when doing a ./sage -sh

#5507 - $ sage -sh -c "echo hi there" # does not work, but should
$ sage -sh -c -c "echo hi there" # works, but shouldn't

There is also a problem that "sage -sh" may pick up the user's
$PATH rather than the one defined in sage-env (which
is how I got into this issue).

The patch below fixes these three problems - but it may
not be what developers want. Specifically, it will set the
prompt to be "sage $" for all shells (with the exception of
csh which does not have a prompt environment variable and
so the prompt gets set to "%"). Note that with the patch
the prompt is NOT listing the current directory.

Do developers prefer that a sage-sub-shell prompt list
the current directory?

If so, I will have another think about this. If not, would
a kind person please check in the patch.

Mariah

--- sage-sage.old 2009-09-25 10:52:08.278703000 -0400
+++ sage-sage.new 2009-09-25 15:11:21.214214000 -0400
@@ -374,41 +374,37 @@
echo "with other copies of Sage!"
echo ""
SHELL_NAME=`basename $SHELL`
- if [ $# -eq 0 ]; then
- SHELL_OPTS=""
- else
- shift
- echo "Bypassing shell configuration files ..."
- echo
- # We must start a new shell with no .profile or .bashrc files
- # processed, so that we know our path is correct
- PS1="sage$ "
- export PS1
- case $SHELL_NAME in
- bash)
- SHELL_OPTS=" --norc"
- ;;
- csh)
- SHELL_OPTS=" -f"
- ;;
- ksh)
- SHELL_OPTS=" -p"
- ;;
- sh)
- SHELL_OPTS=" --norc"
- ;;
- tcsh)
- SHELL_OPTS=" -f"
- ;;
- zsh)
- SHELL_OPTS=" -f -d"
- ;;
- *)
- echo "Unknown shell: $SHELL!"
- echo "Exiting Sage."
- exit 1
- esac
- fi
+
+ echo "Bypassing shell configuration files ..."
+ echo
+ # We must start a new shell with no .profile or .bashrc files
+ # processed, so that we know our path is correct
+ PS1="sage$ "
+ export PS1
+ case $SHELL_NAME in
+ bash)
+ SHELL_OPTS=" --norc"
+ ;;
+ csh)
+ SHELL_OPTS=" -f"
+ ;;
+ ksh)
+ SHELL_OPTS=" -p"
+ ;;
+ sh)
+ SHELL_OPTS=" --norc"
+ ;;
+ tcsh)
+ SHELL_OPTS=" -f"
+ ;;
+ zsh)
+ SHELL_OPTS=" -f -d"
+ ;;
+ *)
+ echo "Unknown shell: $SHELL!"
+ echo "Exiting Sage."
+ exit 1
+ esac
$SHELL_NAME $SHELL_OPTS "$@"

echo Exited Sage subshell.

Minh Nguyen

unread,
Sep 25, 2009, 4:53:23 PM9/25/09
to sage-...@googlegroups.com
Hi Mariah,

On Sat, Sep 26, 2009 at 6:04 AM, Mariah Lenox <mariah...@gmail.com> wrote:
>
> The open trac tickets #4644 and #5507 discuss
> problems with "sage -sh", specifically
>
> #4644 - No new prompt when doing a ./sage -sh

I can confirm that your patch fixes this issue:

{{{
[mvngu@sage sage-4.1.1]$ ./sage -sh

Starting subshell with Sage environment variables set.
Be sure to exit when you are done and do not do anything


with other copies of Sage!

Bypassing shell configuration files ...

sage$ exit
exit
Exited Sage subshell.
}}}


> #5507 - $ sage -sh -c "echo hi there" # does not work, but should

It also fixes this one as well:

{{{
[mvngu@sage sage-4.1.1]$ ./sage -sh -c "echo hi there"

Starting subshell with Sage environment variables set.
Be sure to exit when you are done and do not do anything


with other copies of Sage!

Bypassing shell configuration files ...

hi there
Exited Sage subshell.
}}}

> $ sage -sh -c -c "echo hi there" # works, but shouldn't

This one still works:

{{{
[mvngu@sage sage-4.1.1]$ ./sage -sh -c -c "echo hi there"

Starting subshell with Sage environment variables set.
Be sure to exit when you are done and do not do anything


with other copies of Sage!

Bypassing shell configuration files ...

hi there
Exited Sage subshell.
}}}

> There is also a problem that "sage -sh" may pick up the user's
> $PATH rather than the one defined in sage-env (which
> is how I got into this issue).

With the patch, the user's $PATH is picked up, but variables in
sage-env are prepended to it:

{{{
[mvngu@sage sage-4.1.1]$ echo $PATH
/home/mvngu/usr:/home/mvngu/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
[mvngu@sage sage-4.1.1]$
[mvngu@sage sage-4.1.1]$ ./sage -sh

Starting subshell with Sage environment variables set.
Be sure to exit when you are done and do not do anything


with other copies of Sage!

Bypassing shell configuration files ...

sage$ echo $PATH
/scratch/mvngu/build/sage-4.1.1:/scratch/mvngu/build/sage-4.1.1/local/bin:/home/mvngu/usr:/home/mvngu/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
sage$ exit
exit
Exited Sage subshell.
}}}


> The patch below fixes these three problems - but it may
> not be what developers want. Specifically, it will set the
> prompt to be "sage $" for all shells (with the exception of
> csh which does not have a prompt environment variable and
> so the prompt gets set to "%"). Note that with the patch
> the prompt is NOT listing the current directory.
>
> Do developers prefer that a sage-sub-shell prompt list
> the current directory?

Yes, that would be nice.

--
Regards
Minh Van Nguyen

Paulo César Pereira de Andrade

unread,
Sep 25, 2009, 5:10:24 PM9/25/09
to sage-...@googlegroups.com
2009/9/25 Minh Nguyen <nguye...@gmail.com>:

Possibly a bit out of context. But I was hit by "sage -sh"
yesterday. I run "./sage -sh" to make some tests, and gone do other
duties in the meantime. Then, I forgot I was under a sage 4.1.1 shell
in that xterm, and things started working incorrectly.
Curiously, I had been debugging a problem with
java-1.6-openjdk-plugin and java-1.6-sun-plugin, where only the sun
plugin works in my Mandriva setup, when loading the jmol plugin. (I
was testing/comparing both, the mandriva rpm package, and sage-4.1.1
binary downloaded from a sagemath mirror).
Then, after playing with install/uninstall of several packages, I
ended up in a state where firefox would always refuse to start, and
the reason was LD_LIBRARY_PATH, because I was starting firefox from
the xterm that was running "sage -sh".

Paulo

Mariah

unread,
Sep 28, 2009, 10:10:52 AM9/28/09
to sage-devel
Minh suggests that developers would prefer to have
the current directory listed in a sage sub-shell prompt.

The patch below causes the current directory to be
listed on one line and then "sage subshell$ " on the
next. Hopefully this will help people like Paulo
remember when they are in a sage subshell.

# ./sage -sh

Starting subshell with Sage environment variables set.
Be sure to exit when you are done and do not do anything
with other copies of Sage!

Bypassing shell configuration files ...

/home/mariah/sage/sage-4.1.1-x86_64-Linux-core2-fc
sage subshell$ echo hi
hi
/home/mariah/sage/sage-4.1.1-x86_64-Linux-core2-fc
sage subshell$


If this is acceptable, would a kind developer check
this in.

Mariah

--- sage-sage.old 2009-09-25 10:52:08.278703000 -0400
+++ sage-sage 2009-09-28 09:59:12.151547000 -0400
+ PS1="${PWD}\nsage subshell$ "

Dan Drake

unread,
Sep 28, 2009, 7:26:00 PM9/28/09
to sage-...@googlegroups.com
On Mon, 28 Sep 2009 at 07:10AM -0700, Mariah wrote:
> If this is acceptable, would a kind developer check this in.

I converted your patch to our Mercurial format and posted it at ticket
#4644, and left a comment on ticket #5507.

Dan

--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------

signature.asc
Reply all
Reply to author
Forward
0 new messages