Displaying a new line on the prompt

  • Open the file ~/.bashrc (or /etc/bash.bashrc if it should work globally for all users).

  • Locate the variable called PS1.

  • Simply put an \n at the end of the value of the PS1 variable.


I prefer using a custom .bashrc file

First, append the following lines to your ~/.bashrc file:

##
## INCLUDE CUSTOM `.bashrc` CODE
##
if [ -f ~/.bashrc_custom ]; then
    . ~/.bashrc_custom
fi

Create the custom file:

touch ~/.bashrc_custom`

Finally open it and put the following lines into:

# File: $HOME/.bashrc_custom
# THIS FILE IS A USER-CUSTOM BASHRC FILE TO KEEP CLEAN THE DEFAULT ~/.barshrc FILE.
# PUT THERE ANY CUSTOM CODE MANUALLY ADDED BY YOU


# Add a new line at the end of the command prompt
#PS1=${PS1}\\n
PS1=${PS1%?}
PS1=${PS1%?}\n'$ '

The next opened shell session will looks like following:

user@host:~
$ <your-next-command-will-be-rendered-here>

This was painful, but in the end, due to a complicated custom PS1 setup with custom colors, this is the only thing that worked for me:

new_line() {
    printf "\n$ "
}
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]$(new_line)'
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)$(new_line)'
fi

Tags:

Bash

Scripts