Pattern to ignore 'history numlines' in HISTIGNORE, bash

1.7k Views Asked by At

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.

2

There are 2 best solutions below

10
On BEST ANSWER

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]*)'
1
On

To have multiple patterns you can separate them with a :

Like this:

HISTIGNORE="&:exit:pwd:rm *:history *:[ \t]*"