gpt4 book ai didi

linux - bash shell 脚本是否保留其命令历史记录?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:39:54 26 4
gpt4 key购买 nike

bash shell 脚本是否会保留它执行的命令的历史记录,例如 .bash_history

我很好奇。

最佳答案

不,它不会: https://www.gnu.org/software/bash/manual/html_node/Bash-History-Facilities.html

9.1 Bash History Facilities

When the -o history option to the set builtin is enabled (see The Set Builtin), the shell provides access to the command history, the list of commands previously typed.

要获取当前设置,请使用 set -o 命令。在 interactive shells (使用 bash 的 -i 选项或来自登录或终端的常用 bashes)它打印 history on。当在脚本中使用时(bash -c 'set -o' 或当您在没有分配 tty 的情况下执行 ssh machine bash 时)它是未设置的:history off.

https://www.gnu.org/software/bash/manual/html_node/Interactive-Shell-Behavior.html

6.3.3 Interactive Shell Behavior - When the shell is running interactively, it changes its behavior in several ways.

  1. Command history (see Bash History Facilities) and history expansion (see History Interaction) are enabled by default. Bash will save the command history to the file named by $HISTFILE when a shell with history enabled exits.

历史可以通过几个命令在脚本中启用:https://askubuntu.com/questions/546556/how-can-i-use-history-command-in-a-bash-script/https://unix.stackexchange.com/questions/5684/history-command-inside-bash-script - 设置 HISTFILE 和(可选)HISTTIMEFORMAT,使用 set -o history 启用,然后使用 history 命令。

关于linux - bash shell 脚本是否保留其命令历史记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44016084/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com