7

I'm using Debian and today I typed:

exec bash

in my terminal and somehow the user@xxx changed to bash-4.4.

How do I get back the user@xxx? I think it's better for me because for example it shows the path to my current folder etc...

  • Why are you even doing exec bash in the first place? – marcelm Apr 6 '18 at 14:40
  • 1
    exec bash is a nice way to get a clean shell, reloading your ~/.bashrc or whatever config file should be reloaded. – Matthieu Moy Apr 6 '18 at 16:27
  • 7
    You can't reverse an exec operation -- it replaces your current process with a new one. The old process is dead and gone -- you might be able to replace your new process with something more like the old one, but you can't get the specific/actual/original instance back. – Charles Duffy Apr 6 '18 at 16:44
  • 2
    If this is a GUI, close the terminal emulator window and open a new one ;) – Zanna Apr 6 '18 at 17:49
22
exec bash -l

This will replace the current shell session with a bash shell started as a login shell. A login shell will read your .bash_profile (or .bash_login or .profile, whichever it finds first) and other files where your prompt may be defined.

With exec bash, you replaced the current shell session with an interactive shell. This will read .bashrc from your home directory. If you don't set your prompt there, then you will get the default bash prompt.

Without the exec, you would have been able to just exit to get back to your old shell session. With the exec, the old session is now gone.

You may also simply exit the shell and start a new one.

  • 5
    @KronwarsCZ It's very seldom that you will have to change the shell startup files in /etc. It is more common to modify the behaviour on a user by user basis in one's private shell startup files. – Kusalananda Apr 6 '18 at 14:07
0

The user@xxx is called the "prompt". It is set by the PS1 environment variable. In bash, it defaults to bash-<version> which is utterly useless, but in principle a bash configuration file should always set it to something better.

A common case where you would get this is when you just created a ~/.bashrc file that does not include /etc/profile. Without this file, bash was falling back to /etc/profile and you were getting your system's default configuration. With an empty or minimalist ~/.bashrc, only your own configuration is loaded, and you don't get the benefit of what your distro or your sysadmin put in /etc/profile.

Solution: add this to your ~/.bashrc:

if [ -f /etc/profile ]; then
    . /etc/profile
fi

Alternatively, set your prompt yourself by adding something like this (after the snippet above):

PS1="\u\h@\\$ "

(You can customize what appears in the prompt, make it colorful & all with tools like http://ezprompt.net/)

  • 3
    shudder I'm pretty sure you really don't want that in your .bashrc especially if /etc/profile yields output. – Joshua Apr 6 '18 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.