更改所有Bash用户的PS1值

我正在尝试将系统的所有用户($ PS1variables)的提示值更改为相同的值。

我有以下存储在文件/ etc / ps1中:

PS1='` if [ $? -eq 0 ]; then echo -n "\[\033[00;35m\]\u\[\033[01;32m\]@\[\033[00;35m\]\h\[\033[00;32m\](\[\033[01;35m\]\W\[\033[01;32m\])\[\033[00;32m\]\$"; else echo -n "\[\033[00;35m\]\u\[\033[01;31m\]@\[\033[00;35m\]\h\[\033[01;31m\](\[\033[35m\]\W\[\033[31m\])\[\033[00;31m\]\$"; fi`\[\033[0m\]' 

在我的单用户帐户下,我可以将source /etc/ps1添加到我的〜/ .profile文件中(有趣的是,当我添加到〜/ .bashrc时,它不起作用)。 如果我把它添加到/ etc / profile或者/etc/bashrc.basrch中,让所有的用户都可以这样做,什么都不会发生。 我正在试图让这个工作。 这是在Debian 7.1.0(Linux 3.2.46)上。

将你修改的PS1设置添加到/etc/profile.d/custom_ps1.sh/etc/profile.d下的/etc/profile.d是从/etc/profile自动获得的:

 if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi 

每当一个loginshell被产生的时候就被调用。 从bash manpage :

当bash作为交互式loginshell或者作为具有--login选项的非交互式shell调用时,它首先从文件/etc/profile读取和执行命令(如果该文件存在)。 读取该文件后,它将按照该顺序查找~/.bash_profile~/.bash_login~/.profile ,并从第一个存在并读取的第一个中读取和执行命令。 当shell开始禁止这种行为时,可以使用--noprofile选项。