cshell中提示符设置

本文详细介绍了终端提示符的设置方法,特别是tcsh和bash shell下的不同。重点讲解了tcsh中 `%` 符号的各种选项,如 `%n` 代表用户名,`%m` 代表主机名,`%c` 代表当前目录等,并提供了如何自定义提示符的示例。此外,还提到了提示符中关于时间、历史事件号、返回码等相关信息的显示方式。对于终端用户和系统管理员来说,了解这些设置能提升日常工作的效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

终端的提示符可以按如下设置:
set prompt = '[%n@%m %c]$ ’
%n:用户名
%m:主机名
%c:最后的目录.
使用 pwd无效, 因为cshrc文件在shell启动的时候是只读的,不是在每一次文件改变时都读取。
csh和tcsh使用cshrc文件,bash使用bashrc文件。

以下是tcshell常用的提示符设置选项:

optiondescription
%/The current working directory.
%~The current working directory, but with one’s home directory represented by `~’ and other users’ home directories represented by `~user’ as per Filename substitution.`~user’ substitution happens only if the shell has already used `~user’ in a pathname in the current session.
%c[[0]n], %.[[0]n]The trailing component of the current working directory, or n trailing components if a digit n is given. If n begins with `0’, the number of skipped components precede the trailing component(s) in the format `/trailing’. If the ellipsis shell variable is set, skipped components are represented by an ellipsis so the whole becomes `…trailing’. `~’ substitution is done as in `%~’ above, but the `~’ component is ignored when counting trailing components.
%CLike %c, but without `~’ substitution.
%h, %!, !The current history event number.
%MThe full hostname.
%mThe hostname up to the first `.’.
%S (%s)Start (stop) standout mode.
%B (%b)Start (stop) boldfacing mode.
%U (%u)Start (stop) underline mode.
%t, %@The time of day in 12-hour AM/PM format.
%TLike `%t’, but in 24-hour format (but see the ampm shell variable).
%pThe `precise’ time of day in 12-hour AM/PM format, with seconds.
%PLike `%p’, but in 24-hour format (but see the ampm shell variable).
\cc is parsed as in bindkey.
^cc is parsed as in bindkey.
%%A single `%’.
%nThe user name.
%NThe effective user name.
%jThe number of jobs.
%dThe weekday in `Day’ format.
%DThe day in `dd’ format.
%wThe month in `Mon’ format.
%WThe month in `mm’ format.
%yThe year in `yy’ format.
%YThe year in `yyyy’ format.
%lThe shell’s tty.
%LClears from the end of the prompt to end of the display or the end of the line.
%$Expands the shell or environment variable name immediately after the `$’.
%#`>’ (or the first character of the promptchars shell variable) for normal users, `#’ (or the second character of promptchars) for the superuser.
%{string%}Includes string as a literal escape sequence. It should be used only to change terminal attributes and should not move the cursor location. This cannot be the last sequence in prompt.
%?The return code of the command executed just before the prompt.
%RIn prompt2, the status of the parser. In prompt3, the corrected string. In history, the history string.

`%B’, `%S’, `%U’ and `%{string%}’ are available in only eight-bit-clean shells; see the version shell variable.
The bold, standout and underline sequences are often used to distinguish a superuser shell. For example,
> set prompt = "%m [%h] %B[%@]%b [%/] you rang? "
tut [37] [2:54pm] [/usr/accts/sys] you rang? _

If `%t’, `%@’, `%T’, `%p’, or `%P’ is used, and noding is not set, then print DING!' on the change of hour (i.e,:00’ min‐
utes) instead of the actual time.

Set by default to `%# ’ in interactive shells.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值