Linux

更改 linux 外殼

  • July 6, 2020

在我的 Centos7 伺服器上,我為我的使用者提供了不同的 shell。

例如,作為 root 的終端如下所示:

[root@hostname www]#.

終端作為不同使用者的樣子bash-4.2$

如果我鍵入echo $0以獲取目前使用的 shell,我將/bin/bash訪問我的不同使用者和-bash我的 root。

我是否必須為我的不同使用者配置 shell,以使其看起來像我的 root 的 shell?

有沒有辦法使用 Debian ( bash) 中使用的 shell 來查看我所在位置的完整路徑?(root@server:/var/www#而不是root@server www)。

謝謝你的幫助。

聽起來您的使用者缺少骨架文件, default.bashrc.bash_profile,這些文件通常從/etc/skel創建使用者時復製到使用者的主目錄中。如果這些文件失去或損壞,您可以自己複製這些文件。

使用者的提示由 shell 變數 PS1、PS2、PS3、PS4 的值決定。

PS1 – The value of this parameter is expanded and used as the primary prompt string. 
     The default value for Bash is \s-\v\$ .
PS2 – The value of this parameter is expanded as with PS1 and used as the secondary 
     prompt string. The default value for Bash is >
PS3 – The value of this parameter is used as the prompt for the select command
PS4 – The value of this parameter is expanded as with PS1 and the value is printed 
     before each command bash displays during an execution trace.

通常使用者只自定義 PS1。

Bash 允許通過插入一個或多個轉義的特殊字元來自定義這些變數:

\a : ASCII bell character
\d : The date in “Weekday Month Date” format (e.g., “Tue May 26”)
\D{format} : the format is passed to strftime(3) and the result is inserted into
the prompt string; an empty format results in a locale-specific time representation. 
The braces are required
\e : Tne ASCII escape character
\h : The hostname up to the first ‘.’
\H : The full hostname
\j : The number of jobs currently managed by the shell
\l : The basename of the shell's terminal device name
\n : A newline
\s : The name of the shell
\t : The current time in 24-hour HH:MM:SS format
\T : The current time in 12-hour HH:MM:SS format
\@ : The current time in 12-hour am/pm format
\A : The current time in 24-hour HH:MM format
\u : The username of the current user
\v : The current version of bash (e.g., 2.00)
\V : The current release of bash, version and patch level (e.g., 4.12.0)
\w : The current working directory, with $HOME abbreviated with a tilde
\W : The basename of the current working directory, with $HOME abbreviated 
    with a tilde
\! : The history number of this command
\# : The command number of this command
\$ : If the effective UID is 0, a #, otherwise a $
\nnn : The character corresponding to the octal number nnn
\\ : A backslash
\[ : Begin sequence of non-printing characters, which could be used to embed 
    a terminal control sequence into the prompt
\] : End sequence of non-printing characters

例子:

fpm@fpmurphy ~]$ PS1="[\d \t \u@\h:\w ] $ "
[Sun Jul 05 23:44:17 fpm@fpmurphy:~ ] $ 

要在重新啟動或註銷時保留自定義提示,請將提示添加到 users $HOME/.bashrc,或使其成為所有使用者的預設提示,根據您的發行版將其添加到/etc/bashrc或創建一個條目。/etc/bashrc.d

引用自:https://serverfault.com/questions/1024093