Why does bash look different in different flavours of linux/unix? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this questionI'm doing some work on a server that runs CentOS at the moment, and the prompt looks different from the Ubuntu bash command line. I initially thought it was a different shell, but echo $SHELL
showed me that it was still bash.
I was mainly wondering whether this is a configuration thing, and where this is set up, for example, my ubuntu bash prompt:
tom@tom-PC:~$
compared with the CentOS bash command prompt:
[root@server217-174-254-199 ~]#
Aside from the obvious differences in machine name and user (and the # caused by being logged开发者_如何学Go in as root) CentOS has [ ~] around the user@machine whereas ubuntu prefers a simple :~ before the prompt
It's a question of taste: everyone can configure his PROMPT-line with the env-variable PS1.
For example:
PS1='\u@\h:\w$'
gives
user@host:directory$
whereas directory is '~' for your home-dir.
Here it looks this way:
glglgl@schleppiSB [1314183327: Wed Aug 24 2011 12:55:27, 9/62261]
-0 0 ~/p>
even with nice colors. Why? Because my ~/.bashrc
contains the line
PS1='\e[1;32;44m\u\e[1;30m@\e[1;34m\h\e[0m [\e[1;43;33m$(shellprompttemp=$?; LANG=C date +"%s: %a %b %d %Y"; exit $shellprompttemp)\e[1;37m \t\e[0m, \e[1;35m\#\e[0m/\e[1;36m\!\e[0m] \e[1;31;7m${?/#0}\e[0m\e[0m\n$(hg prompt '\''{\e[41;37mhg: {status}\e[0m\n}'\'' 2>/dev/null; dirs -p -v | tac | awk '\''{ $0=sprintf("%2d %s",NR-1,$0); sub(/^ */,"&-"); print; }'\'')> '
With PS1
, you have full control over how your prompt looks like. You get more info with man bash
, section PROMPTING
.
Different distros are preconfigured for different user populations. On a desktop, you mainly just expect to see a simple prompt and maybe the current directory; for a server distro, it is useful for the prompt on each server to be different from every other server, so that you can tell at a glance where you are logged into (the admin typically logs into more than one server at the same time). Other than that, though, it's just a matter of taste, typically the taste of the Bash maintainer for your distro. Out of the box, the default prompt in Bash is just bash$
(where the dollar sign is replaced with a hash sign when you are logged in as root).
精彩评论