A multiline Linux Bash command prompt

Now that I have Linux shell accounts on at least seven different servers, I've changed my Bash login prompt on each server so I can easily see what server I'm logged in to. For instance, on my Valley Programming web server, my command prompt looks like this:

VALPRO:/home/al
> _

With this prompt, the "VALPRO" part reminds me that I'm logged into my Valley Programming server, and the path shown to the right of it changes as I move from one directory to another. I actually type my command on the line beneath that, where the underscore character is shown.

I like this approach because (a) when I'm in some deep subdirectory, I can still see what directory I'm in and (b) it doesn't interfere with the commands I'm typing.

Creating a multiline Bash command prompt

I create this multiline command prompt with this simple entry in the .bash_profile file in my HOME directory:

PS1='
VALPRO:$PWD
> '

There isn't much to say about this, other than:

  • PS1 stands for "prompt symbol, level 1".
  • The $PWD variable is the rough equivalent to typing the 'pwd' command.
  • It's important to use single quotes here instead of double quotes. If you use double quotes, the path that's displayed will never change, and of course that's not helpful at all. (As usual, using single quotes hides the $ from being interpolated by the shell.)

One other thing I should mention is that with this approach I intentionally leave an extra blank line between prompts, so if I just hit the [Enter] key repeatedly, I'll see something like this:

VALPRO:/home/al
> 

VALPRO:/home/al
> _

If that doesn't seem like a good thing, it really is. It makes for a nice separator between command lines, which feels right when you use a multiline command prompt like this.

There are more things you can do with a multiline Bash command prompt, such as show the date and time, but this simple approach has always felt the best to me.

Valley Programming is currently a one-person business, owned and operated by Alvin Alexander. If you’re interested in anything you read here, feel free to contact me at “al” at (“@”) this website name (“valleyprogramming.com”), or at the phone number shown below. I’m just getting back to business here in November, 2021, and eventually I’ll get a contact form set up here, but until then, I hope that works.