大网数据广告活动
服务器运维问答

Azure Cloud Shell history persist across sessions

· 52CE 我爱测

My Azure Cloud Shell history does not persist across sessions (which time out after 10 mins so this is annoying). The .bashrc has # append to the history file, don't overwrite it shopt -s histappend # for setting history length s…

问题原文

原帖链接 · Gaius · CC BY-SA 3.0

My Azure Cloud Shell history does not persist across sessions (which time out after 10 mins so this is annoying). The .bashrc has

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

So this should work, but no .bash_history gets written.

已采纳解答

原帖链接 · Shui shengbao · CC BY-SA 3.0

According to you description, it seems that your shell environment variable does not set correctly. I test on my Azure VM, it works for me. I suggest you could check as the following methods.

1.Check you current shell.

You could use echo $SHELL to get your current shell. .bashrc profile is used for bash shell. If you use other shell, such as csh, it does not work.

2.Check .profile file. Please ensure the following commands are existing.

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

3.Check .profile and .bashrc user and group permission.

-rw-r--r-- 1 shui shui 3771 Aug 31  2015 .bashrc

Update:

Cloud Shell does not save history command to .bash_history. If you want to do this. You could add export PROMPT_COMMAND='history -a' to .bashrc. Such as belwo:

# append to the history file, don't overwrite it
shopt -s histappend
export PROMPT_COMMAND='history -a'

Then you could source .profile. Now, you could find .bash_histroy and store your latest history command.

Notes: It is not recommended to do this, because other people could see you command, this is unsafe behavior.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。