What is the format of shell history files

我们两清 提交于 2019-12-31 07:27:09

问题


My ~/.zsh_history shows:

: 1449561637:0;echo "foobar"

I'm guessing it goes unix timestamp : exit code ; command but what about the space before the timestamp and first colon?

Is there an official spec?


回答1:


As already noted in the comments, the format of the history file depends on the shell and sometimes even on specific settings of the shell.

In your case you are using zsh with the EXTENDED_HISTORY option enabled (either by explicitly setting it or by using csh-emulation). According to the ZSH manual the format of history entries with EXTENDED_HISTORY is as follows:

: <beginning time>:<elapsed seconds>;<command>

So the space before the timestamp is just part of the format and the number between the second colon an the semicolon is actually the time taken by the command and not the exit code.

Note: <elapsed seconds> will always be 0, if the INC_APPEND_HISTORY option is set, because then the history entry is written to the file immediately after entering the command. If you want to log the duration and keep sharing the history between shell sessions, you may want to use INC_APPEND_HISTORY_TIME instead. This writes to the history file only after the command completed.



来源:https://stackoverflow.com/questions/34150889/what-is-the-format-of-shell-history-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!