Search code examples
bashcommand-history

Pattern to ignore 'history numlines' in HISTIGNORE, bash


What would be the correct pattern for ignoring commands such as:

history 10
history 104
history .. #whatever may be the number here

I tried:

HISTIGNORE='history\s+\d*'

but that doesn't work.


Solution

  • The value of HISTIGNORE is a list of shell patterns. Not a list of regular expressions. As such the regular expressions will not work.

    This pattern 'history *[0-9]*' should do what is needed here.

    Edit: Pulling in added information from the comments.

    To also ignore history by itself the simplest solution is to just add history to the value of HISTIGNORE.

    But, when extglob is enabled (and assuming HISTIGNORE honors it) this pattern should cover that as well:

    'history?( *[0-9]*)'