war*_*ren 3 bash history formatting command-line
需要在bash
提示中添加什么格式字符以指示最近的history
项目运行(或当前命令编号,如果可以将 1 添加到最后一个history
条目)?
我的提示字符串是这样的:
\[\033[33m\][\u@\[\033[1;31m\]\h]\]\033[0m {\W}\n\033[1;34m\]\w\]\033[0m >
Run Code Online (Sandbox Code Playgroud)
给我以下显示:
[user@host] {~}
~ >
Run Code Online (Sandbox Code Playgroud)
用户为黄色,主机为红色。括号中的条目是当前目录,大于号之前的条目是完整的pwd
.
我可以将当前命令号附加到第一行,这样我就会有如下内容:
[user@host] {~} (nnn)
~ >
Run Code Online (Sandbox Code Playgroud)
其中(nnn)
在当前(或刚处理)命令数,运行时,如图history
?
从PROMPTING部分bash手册页面:
\! the history number of this command
\# the command number of this command
Run Code Online (Sandbox Code Playgroud)
再往下:
命令号和历史号通常是不同的:一个命令的历史号是它在历史列表中的位置,其中可能包括从历史文件中恢复的命令......,而命令号是命令序列中的位置在当前 shell 会话期间执行。
如果您想要最后一个命令编号,您可以将数字包装在这样的算术评估中:
export PS1='last cmd num: $((\# -1)), this num: \# '
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1411 次 |
最近记录: |