On 15/09/2020 14:44, Vincenzo Nicosia wrote:
On Tue, Sep 15, 2020 at 02:08:16PM +0100, Ottavio Caruso wrote:
Hi,

I have this in ~/.kshrc :

PS1="\u@\h:\w\$ "

which works fine in ksh:

oc@OpenBSD:~$

However, if I open a sh subshell, I get:

\u@OpenBSD:\w$

which is not very nice. The only hack I've found is to append this to
~/.profile:


if [ -n "$KSH_VERSION" ]; then
     if [ -f "$HOME/.kshrc" ]; then
        . "$HOME/.kshrc"
     fi
fi

I wonder if there is a more elegant solution.

Hi,

the more elegant solution is to set ENV appropriately. ~/.profile is
normally read only at login, while sub-shells will source whatever
file is specified in ENV.

This is what I had and it generated the undesired prompt in sh.

You probably mean "interactive shells", not just sub shells. A sub shell could be child of a non login shell as well.

With ENV=~/.khsrc, PS1 is propagated over to sub shells, whether it is ksh or sh, whereas just sourcing ./.khsrc will not export PS1. I don't know why this is. It doesn't make sense to me. Maybe it's just because OpenBSD sh is just ksh in disguise or there might be other reasons that I obviously don't know.

--
Ottavio Caruso

Reply via email to