LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-17-2014, 08:53 AM   #1
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Rep: Reputation: Disabled
A RegEx question.


If I wanna ignore "history" as well as "history " in HISTIGNORE, can I do it with a regular expression?

When I use "history?" it does not cover the first case, so, is there a way to say "any character OR no characters"?

I added two cases explicitly but I assume there is some neat trick?

Cheers!
 
Old 07-17-2014, 11:57 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Not sure where you are, but in regex terms the operators refer to the previous character.
So assuming a standard ERE engine:
Code:
"history ?"
This would look for "history" followed by 0 or 1 space
 
Old 07-18-2014, 07:53 AM   #3
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
That does not seem to work. It works if I do "history " or "history ", but not "history".
I am using Debian 7.5, bash shell.
I'm talking about .bash_profile configuration.
 
Old 07-18-2014, 08:16 AM   #4
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
Btw, I've purchased RegexBuddy, and your solution certainly seems legit, so this might be a limitation in bash, or .bash_profile interpretation?
 
Old 07-18-2014, 08:31 AM   #5
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
In POSIX BRE it should be history[ ]*, but it still does not seem to cover "history"... -.-
 
Old 07-18-2014, 09:05 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Ahhh ... I was not paying enough attention the first time around

You are looking at globbing and not regex so if you simply assign an asterisk to the end you will see no command starting with history:
Code:
HISTIGNORE="history*"
 
Old 07-18-2014, 09:07 AM   #7
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
Can you take it a step further and limit it to one character, and not an unlimited number? I would still like to see history | grep and things in that manner, would like to exclude only "history" and "history "?
 
Old 07-18-2014, 10:58 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Well I am not sure I see the point as I am guessing you are trying to catch a typo, but my suggestion would be you could check out if turning on extgob will help you, or simply place both in HISTIGNORE
 
1 members found this post helpful.
Old 07-18-2014, 01:26 PM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
Code:
HISTIGNORE="history ?$| +"

Last edited by keefaz; 07-18-2014 at 01:28 PM.
 
Old 07-19-2014, 01:43 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
I do not think that will work keefaz as this is not a regex type setting, at least from what I could find.
 
Old 07-21-2014, 05:28 AM   #11
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
Indeed nothing seems to work... Solutions here were fine regex wise, I also made some of my own, but it does not work in .bash_profile.
 
Old 07-21-2014, 05:32 AM   #12
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Not even setting the variable for both options?
 
Old 07-21-2014, 06:05 AM   #13
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
That works of course, but the whole point of my question was to make it more clever and learn something along the way... Just seemed kinda noobish.
grail, I'm going to mark your answer as solved regardless, thanks for spending your time on this with me.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Question about regex circus78 Linux - General 6 11-29-2013 03:55 AM
[SOLVED] Regex question Steve W Programming 10 05-04-2011 02:43 AM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 02:10 AM
A question about regex trist007 Linux - Newbie 12 09-16-2010 02:20 PM
regex question Toadman Linux - General 0 12-30-2005 01:59 PM


All times are GMT -5. The time now is 02:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration