The prompt variable $PS1
was probably not set, so the built-in default \s-\v\$
is used.
When bash starts up interactively, it sources a configuration file, usually either ~/.bashrc
or ~/.bash_profile
, presuming they exist, and this is how a fancier prompt is set. From man bash
:
INVOCATION
[...]
When bash is invoked as an interactive login shell, or as a
non-interactive shell with the --login
option, it first reads and executes commands from the file /etc/profile, if that file exists. After
reading that file, it looks for ~/.bash_profile, ~/.bash_login, and
~/.profile, in that order [...]
[...] When an interactive shell that is not a login shell is started, bash reads and executes commands from
~/.bashrc, if that file exists.
Not having your prompt set can occur in two different contexts then, login shells and non-login shells. If you use a display manager to log directly into the GUI, you don't encounter login shells unless you switch to a virtual console (via, e.g. CtrlAlt + F1 to F6). However, you can test your bash login profile in the GUI by opening a new login shell explicitly: bash -l
.
Problem occurs with non-login shells
If the problem occurs with, e.g., normal GUI terminals, then either your ~/.bashrc
is missing, or it has been edited to exclude sourcing a global file, probably /etc/bashrc
.
If ~/.bashrc
does not exist, there should be a /etc/skel/.bashrc
used to create it for new users. Simply copy that file into your home directory, and your default prompt should come back for the next new shell you open.
If ~/.bashrc
does exist, check to see if there is a line somewhere that sources /etc/bashrc
:
. /etc/bashrc
-OR-
source /etc/bashrc
If not, check if that file exists (it should, at least on most linux distros) and add such a line to your ~/.bashrc
.
Problem occurs with login shells
If the problem occurs with login shells as well as non-login shells, the problem is probably the same as above. If it occurs only with login shells, you either don't have one of the files mentioned for login shells under the INVOCATION quote above, or they don't source your ~/.bashrc
, which is normal on most linux distros. If none of those files exists, create ~/.bash_profile
with this in it:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
This allows you, for the most part, to keep your configuration in one file (~/.bashrc
).
If no matter what you do you cannot get a prompt back, you can create one and put it into ~/.bashrc
this way:
if [ "$PS1 ]; then
PS1= .... # see below
fi
This is because $PS1 is set and has a default value for interactive shells, and you don't want to set it otherwise since other things may use this value to determine whether this is an interactive environment.
The bash man page contains a section PROMPTING which describes how to set a prompt with dynamic features such as your user name and current working directory, which would be, e.g.,:
PS1="\u \w:"
There's a guide to using color here. Pay attention to the fact that you should enclose non-printed characters in \[
and \]
(there's a discussion of this at the end of the answer about colors).
You've completely banjanxed the Bourne Again shell's idea of what's been printed and what it has to erase/rewrite as it displays command history and lets you edit the command line.
Breaking your prompt down into sections:
\[\e]0;\u@\h: \w\a\]
— non-printing characters, properly enclosed
${debian_chroot:+($debian_chroot) }
— printing characters only, presumably
\[\033[01;36m\]
— non-printing characters, properly enclosed
\u@\h
— printing characters only
\[\033[00m\]
— non-printing characters, properly enclosed
\033[01;34m\]
— non-printing characters, improperly enclosed so the Bourne Again shell does not know that they are
\w\033[00m\]
— an erroneous mixture of printing and non-printing characters
[$(type __git_ps1 >/dev/null 2>&1 && __git_ps1 "(%s)")]
— printing characters only, presumably
I've given this advice before, but it is general advice that applies here as well:
- Use either
\e
or \033
consistently, for your own sanity.
- Make your
\[
and \]
strictly matching non-nesting pairs.
- Make sure that all non-printing sequences are within
\[
and \]
(and that, conversely, that all printing sequences are not).
(This is why I personally prefer the Z Shell and its alternative prompt expansion mechanism for when I want wacky coloured prompts. It knows that things like %F{green}
aren't printing sequences, without having to be told; and it also works out the correct escape sequences from terminfo
, without having them hardwired.)
Best Answer
You probably have your own
PS1
definitions in~/.bashrc
(unless you are root) overriding the system-wide/etc/bash.bashrc
(which is without colors). You should editPS1
there.In my
~/.bashrc
thePS1
stuff looks like this (default Debian stretch):The first definition is the one with colors. Change
\w
to\W
in your~/.bashrc
and you should be good.