역사 -a는 bash에서 작동하지 않습니다

역사 -a는 bash에서 작동하지 않습니다

내가 뭐 잘못 했어요? 매뉴얼 페이지의 지침을 따르고 있다고 생각하지만 아무런 효과가 없습니다.

[501] $ history | tail
  492  echo 3
  493  echo 4
  494  echo 5
  495  echo 6
  496  echo 7
  497  echo 8
  498  echo 9
  499  echo 10
  500  PS1='[\!] \$ '
  501  history | tail
[502] $ tail ~/.bash_history 
echo 1
echo 2
echo 3
echo 4
echo 5
echo 6
echo 7
echo 8
echo 9
echo 10
[503] $ history -a
[504] $ tail ~/.bash_history 
echo 1
echo 2
echo 3
echo 4
echo 5
echo 6
echo 7
echo 8
echo 9
echo 10
[505] $ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)
Copyright (C) 2007 Free Software Foundation, Inc.
[506] $ 

tail ~/.bash_history두 번째로 명령의 출력이 달라져야 하지 않습니까?

답변1

이는 Apple 특유의 현상인 것 같습니다. (저는 Mac OS 10.11.6 El Capitan을 사용하고 있습니다.)

HISTFILE가치관은 직접적인 원인입니다.

[512] $ echo $HISTFILE
/Users/Wildcard/.bash_sessions/8BC6B122-0D74-445B-B6A0-7D4D446598CB.historynew

그런데 해당 변수를 설정하지 않았으니 어디에 설정되어 있나요?

아아 그렇구나 .. 댓글을 보니 제가 설정도 안하고 직접 시도하다 /etc/bashrc_Apple_Terminal보니 우연히 만난 것 같네요 . histappend를 켜거나 HISTTIMEFORMAT 변수를 설정하면 세션 재개 지원 코드를 건너뛰도록 코딩했습니다.history -ashopt -s histappend

이 섹션에 대한 인라인 문서는 다음과 같습니다.

# Resume Support: Save/Restore Shell State
#
# Terminal assigns each terminal session a unique identifier and
# communicates it via the TERM_SESSION_ID environment variable so that
# programs running in a terminal can save/restore application-specific
# state when quitting and restarting Terminal with Resume enabled.
#
# The following code defines a shell save/restore mechanism. Users can
# add custom state by defining a shell_session_save_user_state function
# that writes restoration commands to the session file at exit. e.g.,
# to save a variable:
#
#   shell_session_save_user_state() { echo MY_VAR="'$MY_VAR'" >> "$SHELL_SESSION_FILE"; }
#
# During shell startup the session file is executed. Old files are
# periodically deleted.
#
# The default behavior arranges to save and restore the bash command
# history independently for each restored terminal session. It also
# merges commands into the global history for new sessions. Because
# of this it is recommended that you set HISTSIZE and HISTFILESIZE to
# larger values.
#
# You may disable this behavior and share a single history by setting
# SHELL_SESSION_HISTORY to 0. There are some common user customizations
# that arrange to share new commands among running shells by
# manipulating the history at each prompt, and they typically include
# 'shopt -s histappend'; therefore, if the histappend shell option is
# enabled, per-session history is disabled by default. You may
# explicitly enable it by setting SHELL_SESSION_HISTORY to 1.
#
# The implementation of per-session command histories in combination
# with a shared global command history is incompatible with the
# HISTTIMEFORMAT variable--the timestamps are applied inconsistently
# to different parts of the history; therefore, if HISTTIMEFORMAT is
# defined, per-session history is disabled by default.
#
# Note that this uses PROMPT_COMMAND to enable per-session history
# the first time for each new session. If you customize PROMPT_COMMAND
# be sure to include the previous value. e.g.,
#
#   PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }your_code_here"
#
# Otherwise, the per-session history won't take effect until the first
# restore.
#
# The save/restore mechanism is disabled if the following file exists:
#
#   ~/.bash_sessions_disable

관련 정보