Date:        Mon, 15 Dec 2025 22:32:02 +0000 (UTC)
    From:        RVP <[email protected]>
    Message-ID:  <[email protected]>

  | Note that there's no '\n' in that PS1. Don't know how to get a literal '\n'
  | into PS1.

Well, the obvious way, based upon the way you did it, would be:

PS1='
$(date +"%a %b %e  %H:%M:%S")
${PSlit}$(tput bold setaf 1)${PSlit} $USER@$(hostname) $(pwd) ${PSlit}$(tput 
sgr0)${PSlit} # '

(Inside a quoted string, '' "" or $'' forms, a newline is just a character,
no different than any other character - except for "" and $'' forms, if it
is preceded by a '\'.)

Or you could use $'' instead of '' and get

PS1=$'\n$(date +"%a %b %e  %H:%M:%S")\n${PSlit}$(tput bold setaf 1)${PSlit} 
$USER@$(hostname) $(pwd) ${PSlit}$(tput sgr0)${PSlit} # '

Also, if you're going to use cmdsubs, and $(pwd) instead of $PWD,
and $(hostname) instead of $HOSTNAME you may as well do as requested as:

PS1=$'\n$(date +"%a %b %e  %H:%M:%S")\n${PSlit}$(tput bold setaf 1)${PSlit} 
$USER@$(hostname -s) $(case $PWD in /) printf /;; "$HOME"*) printf %s 
\~"${PWD#"${HOME}"};; *) printf %s "${PWD}";; esac) ${PSlit}$(tput 
sgr0)${PSlit} # '

I wonder what the difference between tput setaf and tput setf is ?

And while I am here, in the example I cut & pasted from sh's man page,
I didn't notice that mandoc had inserted \u00A0 chars instead of spaces.
Why it does that when outputting to a terminal I have no idea, a space
is a space to a terminal, unbreakable or breakable makes no difference
to it (it makes a difference to things which will reformat the output,
terminals don't do that.)

Anyway, those unbreakable spaces should be just ordinary ones in any
use of that example.

When I cut & pasted it, they looked like ordinary spaces to me!

kre

Reply via email to