Is it possible to insert a new line in a prompt of Bourne Shell ?

In order to let the prompt first shows the hostname and path in one line, then starts a new line and allows users to insert a command. I set the PS1 value to '\[H] \W \$ '`echo -e "\n"`, that is:
Code:
PS1='[\H] \W \$ '`echo -e "\n"`
then I get a prompt like this:
Code:
[FreeBSD] /root/work # somecommand
the new line seems does not work in PS1, but if I change it to
Code:
PS1='[\H] \W \$ '`echo -e "\n+ "`
the corresponding prompt becomes
Code:
[FreeBSD] /root/work #
+ somecommand
Can some one explain why the tail '+' helps the new line show in the terminal?

And the new prompt seems to cannot handle a long command correctly. That is if the command is longer than the length of a terminal, then the command will not be shown correctly once we use historic record (up arrow or down arrow in keyboard) to type it again.
 
Why the weird echo -e "\n" construct? Simply echo an empty line: echo "". Besides that, you can use \n the same way you can use \W:
Code:
PS1='[\H] \W \$ \n'

Edit: this works for Bash, not /bin/sh which, strictly speaking, is the Almquist Shell, although compatible it's not the Bourne Shell.

But I would recommend setting your user's shell to tcsh(1), which is much easier to use interactively.
 
Back
Top