我目前正在嘗試使用我的新 Macbook Pro M1 了解有關 CLI 的更多資訊,并嘗試自定義我的 promt。
在我的主目錄中,它顯示:
johndoe@Johns-MacBook-Pro ~ %
為了了解有關此提示的更多資訊,我輸入了:
echo $PS1
// output: %n@%m %1~ %#
變數 n 和 m 不符合網上找到的解釋:https ://www.howtogeek.com/307701/how-to-customize-and-colorize-your-bash-prompt/
當他們參考以下環境變數串列時:
- \h = 主機名
- \u = 用戶名
- \w = 當前目錄
- \W = 當前目錄的基本名稱
- \d = 當前日期
- \n = 換行符
- ...
根據這些來源,此命令:
PS1="\u:\w\$ "
應導致以下提示:
user:working_directory$
似乎變數已經改變,從 \ 到 % 的字符也發生了變化。不幸的是,我找不到有關新變數的任何資訊。
有沒有人知道更多或有解釋的鏈接?
uj5u.com熱心網友回復:
您使用的是 zsh,而不是 bash。提示序列的描述在 zshmisc(1) 中進行了解釋(型別man 1 zshmisc太看它)。作為參考,它說:
%n $USERNAME.
%m The hostname up to the first `.'. An integer may follow the `%'
to specify how many components of the hostname are desired.
With a negative integer, trailing components of the hostname are
shown.
%~ As %d and %/, but if the current working directory starts with
$HOME, that part is replaced by a `~'. Furthermore, if it has a
named directory as its prefix, that part is replaced by a `~'
followed by the name of the directory, but only if the result is
shorter than the full path; see Dynamic and Static named direc‐
tories in zshexpn(1).
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/425665.html
