Tuesday, September 15, 2020

Re: How do you get different $PS1 for /bin/sh and /bin/ksh?

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.

HTH

--

No comments:

Post a Comment