AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / unix / Perguntas / 473581
Accepted
Wildcard
Wildcard
Asked: 2018-10-06 16:20:40 +0800 CST2018-10-06 16:20:40 +0800 CST 2018-10-06 16:20:40 +0800 CST

history -a não funciona no bash

  • 772

Estou fazendo algo errado? Acho que estou seguindo as instruções da página de manual, e isso não está surtindo nenhum efeito.

[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] $ 

A saída do comando não deveria tail ~/.bash_historyser diferente na segunda vez?

bash command-history
  • 1 1 respostas
  • 2121 Views

1 respostas

  • Voted
  1. Best Answer
    Wildcard
    2018-10-06T16:31:56+08:002018-10-06T16:31:56+08:00

    Parece que isso é algo específico da Apple. (Estou usando o Mac OS 10.11.6 El Capitan.)

    Meu HISTFILEvalor é a causa imediata:

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

    Mas como eu não defino essa variável, onde ela está sendo definida?

    Ah, está em /etc/bashrc_Apple_Terminal. E pelos comentários, parece que só encontrei isso porque tentei history -apor si só, sem nunca configurar shopt -s histappend. Eles o codificaram para que, se você ativar histappend ou definir a variável HISTTIMEFORMAT, eles ignorem o código de suporte de retomada de sessão.

    Aqui está a documentação em linha para essa seção:

    # 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
    
    • 6

relate perguntas

  • exportar variáveis ​​​​env programaticamente, via stdout do comando [duplicado]

  • Problema estranho ao passar variáveis ​​do arquivo de texto

  • Enquanto a linha lê mantendo os espaços de escape?

  • ordem de substituição de processos `te` e `bash`

  • Execute um script muito lento até que seja bem-sucedido

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Como exportar uma chave privada GPG e uma chave pública para um arquivo

    • 4 respostas
  • Marko Smith

    ssh Não é possível negociar: "nenhuma cifra correspondente encontrada", está rejeitando o cbc

    • 4 respostas
  • Marko Smith

    Como podemos executar um comando armazenado em uma variável?

    • 5 respostas
  • Marko Smith

    Como configurar o systemd-resolved e o systemd-networkd para usar o servidor DNS local para resolver domínios locais e o servidor DNS remoto para domínios remotos?

    • 3 respostas
  • Marko Smith

    Como descarregar o módulo do kernel 'nvidia-drm'?

    • 13 respostas
  • Marko Smith

    apt-get update error no Kali Linux após a atualização do dist [duplicado]

    • 2 respostas
  • Marko Smith

    Como ver as últimas linhas x do log de serviço systemctl

    • 5 respostas
  • Marko Smith

    Nano - pule para o final do arquivo

    • 8 respostas
  • Marko Smith

    erro grub: você precisa carregar o kernel primeiro

    • 4 respostas
  • Marko Smith

    Como baixar o pacote não instalá-lo com o comando apt-get?

    • 7 respostas
  • Martin Hope
    rocky Como exportar uma chave privada GPG e uma chave pública para um arquivo 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add retorna com: "Erro ao conectar ao agente: nenhum arquivo ou diretório" 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll status systemctl mostra: "Estado: degradado" 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim Como podemos executar um comando armazenado em uma variável? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S Por que /dev/null é um arquivo? Por que sua função não é implementada como um programa simples? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 Como ver as últimas linhas x do log de serviço systemctl 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - pule para o final do arquivo 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla Por que verdadeiro e falso são tão grandes? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis Substitua a string em um arquivo de texto enorme (70 GB), uma linha 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya Por que o Linux usa LF como caractere de nova linha? 2017-12-20 05:48:21 +0800 CST

Hot tag

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve