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



## chuan huang (Dec 29, 2016)

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:

```
PS1='[\H] \W \$ '`echo -e "\n"`
```
then I get a prompt like this:

```
[FreeBSD] /root/work # somecommand
```
the new line seems does not work in PS1, but if I change it to

```
PS1='[\H] \W \$ '`echo -e "\n+ "`
```
the corresponding prompt becomes

```
[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.


----------



## SirDice (Dec 29, 2016)

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:

```
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.


----------



## IPTRACE (Dec 29, 2016)

I use csh() and when I add \n It works as you expect.

```
set prompt = "%N@%m:%~ %# \n"
```


----------

