终端 - 用“$”代替 MyComputer:~ me$

Hal*_*lst 4 osx bash prompt terminal

现在在我的 MacOS X 终端中,我拥有MyComputer:~ me$所有命令。

在我看到的一些视频中,他们刚刚$- 少了很多杂乱,这是怎么做到的?

Gil*_*il' 7

此文本由您的shell打印,称为prompt

你的 shell 可能是bash。提示设置在 bash 的初始化文件中,该文件.bashrc位于您的主目录中。具体来说,提示是由PS1变量设置的。它的值可以包含在显示提示时由某个值替换的转义序列。例如,MyComputer:~ me$提示设置的结果,如

PS1='\h:\w \u\$ '  # host name colon working directory space user name dollar space
Run Code Online (Sandbox Code Playgroud)

尝试在您的末尾添加以下行.bashrc(如果不存在则创建它):

PS1='\$ '
Run Code Online (Sandbox Code Playgroud)

如果这没有改变任何东西,那是因为您有一个登录 shell 并且没有正确的.bash_profile. 有关说明,请参阅.bashrc 和 .bash_profile 之间的差异。小故事:创建一个.bash_profile包含

if [ -r ~/.profile ]; then . ~/.profile; fi
case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac
Run Code Online (Sandbox Code Playgroud)