recentpopularlog in

kme : historyexpansion   6

Preserve bash history in multiple terminal windows - Unix & Linux Stack Exchange
True dat:
@Oli wrote, "I can't think of an intelligent way to do it where existing terminals only see their own history but new ones see a chronologically accurate list of commands." How about (untried): export PROMPT_COMMAND="history -a; $PROMPT_COMMAND". Existing shells will add each command to the history file for new shells to see, but only show their own histories.


Many solutions proposed, all with caveats, but this is what I decided on:

<code class="language-bash">
HISTCONTROL=ignoredups:erasedups # no duplicate entries
HISTSIZE=100000 # big big history
HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite

# append current history list to the history file after each command finishes
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }history -a"</code>

This appends lines to the history file after each command, which makes them available in other sessions, but up arrow will still reverse through the history only for the current session, which is probably less confusing.

You can bring in commands from other sessions (which have been written to the history file) with 'history -n'. Depending on the setting of 'HISTCONTROL', these might end up getting written out to the history file again, though. ¯\_(ツ)_/¯
bash  history  histfile  historyexpansion  frustration  configfile  forthecomments  solution 
july 2019 by kme
bash - Multi-line, double quoted string triggers history expansion on subsequent single-quoted commands it gets piped to - Stack Overflow | https://stackoverflow.com/
Makes more sense now why things like `echo "Hi there!"` don't work, but `echo "Hi there! "` do.
It is not a bug.

After asking this in the bash-bugs mailing list, I got the following answer:
History expansion is explicitly line-oriented.

It doesn't know about shell state, especially shell quoting state, that spans lines.

It does know about vaguely shell-like quoting that's common across a large set of Unix utilities -- since the history and readline libraries are used outside the shell -- and that a double quote introduces a quoted string in which single quotes are not significant and don't inhibit history expansion.
Upvote for documenting this, but that's insane behavior. – tripleee Jun 20 '16 at 8:42
bash  quoting  historyexpansion  history  weirdness  annoyance  gotcha  solution  fuckina 
november 2017 by kme
bash - echo "#!" fails -- "event not found" - Stack Overflow | https://stackoverflow.com/
The ! character is used for csh-style history expansion.

If you do not use this feature, set +o histexpand (aka set +H) turns off this behavior. It is turned off for scripts, but often enabled for interactive use.

As a workaround, you can use single quotes instead of double quotes.

Except when the single-quoted string is downstream of a double-quoted one in a pipeline as noted in https://stackoverflow.com/a/37917491/785213.
bash  historyexpansion  shellscripting  errormessage  weirdness  annoyance  solution 
november 2017 by kme

Copy this bookmark:





to read