4

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.

4
  • 3
    That uses shell patterns not regular expressions. HISTIGNORE='history [0-9]*' might work. Aug 27, 2014 at 13:14
  • How about optional number of spaces? Is that possible, beacause right now history 20 got recorded?
    – branquito
    Aug 27, 2014 at 13:19
  • 1
    Try 'history *[0-9]*' Aug 27, 2014 at 13:19
  • Now history only by itself is being remembered. :) Why is that, when spaces and digits are 0 or more?
    – branquito
    Aug 27, 2014 at 13:25

2 Answers 2

4

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]*)'
10
  • 1
    That is a good question. I'm not sure. If you turn on extglob (and if HISTIGNORE honors that) you can use 'history?( \*[0-9]*) to match history too I think. But that's not exactly a satisfactory answer. Aug 27, 2014 at 13:30
  • 1
    I doubt it. I believe it just enabled previously erroring pattern strings. So it shouldn't affect anything that worked before and just allow things that didn't work before (well, it does change when history expansion for ! is triggered a little bit by disabling !( as a context for history expansion). But you could just add history to HISTIGNORE also. Aug 27, 2014 at 13:38
  • 1
    It won't break that. It only stops the ! in a !( pair from being considered for expansion I believe. The man page talks about it briefly. "Several characters inhibit history expansion if found immediately following the history expansion character, even if it is unquoted: space, tab, newline, carriage return, and =. If the extglob shell option is enabled, ( will also inhibit expansion." Aug 27, 2014 at 13:44
  • 1
    That being said history expansion is a weird weird beast and if I didn't also routinely use things like !! and !$ I would turn it off entirely. Aug 27, 2014 at 13:44
  • 1
    Bah, that shouldn't be visible. I was trying to prevent SO from doing this to the range but clearly it doesn't do that in *code*. The correct pattern should be 'history?( *[0-9]*)'. Aug 27, 2014 at 13:48
1

To have multiple patterns you can separate them with a :

Like this:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.