如何在csh提示符上显示当前日期和时间?

huangapple go评论87阅读模式
英文:

How to have current date and time on csh prompt?

问题

我试图将当前日期和时间放入csh提示符中。对于bash,这个方法是有效的。

如果提示符写成"date",在命令执行完毕后不会更新。如果写成'date',终端会显示一个"date"字符串。

这个实验

英文:

I am trying to put the current date and time in csh prompt. The same is working for bash.

If the prompt is written "date", it is not updating when finishing the command. When written 'date', there is a date string in the terminal.

The experiment

答案1

得分: 2

set prompt='%w %D %Y %P %# '

在tcsh中可行。

原始C shell几乎不在其提示变量内部进行解释。在某些情况下,您可以绕过此问题,但我认为您无法使用原始csh实现您想要的效果。

更新:使用precmd设置提示要灵活得多-这是在显示提示之前每次执行的“命令”。您可以将其别名为任何您喜欢的内容。例如:

alias precmd set prompt='"date"'

将正确更新。由于这使用日期设置提示,我假设它将尊重时区设置。

您可以将日期更改为任何您喜欢的内容!

英文:
set prompt='%w %D %Y %P %# ' 

will work with tcsh.

The original C shell does almost no interpretation inside its prompt variable. You can work around this in some cases I don't think that you can achieve what you want with the original csh.

UPDATE: setting the prompt is much more flexible using precmd - this is a "command" that gets executed every time before the prompt is shown. You can alias it to whatever you like. For example:

alias precmd set prompt='"`date`"'

will update properly. Since this uses date to set the prompt I assume it will respect time zone settings.

You can change date to whatever you wish!

huangapple
  • 本文由 发表于 2023年5月25日 19:14:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331681.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定