LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-31-2009, 12:41 PM   #1
ciphyre
Member
 
Registered: Aug 2008
Distribution: FEDORA, RHEL, SLES
Posts: 51

Rep: Reputation: 15
Pattern matching in a bash case statement using regex


I keep finding conflicting information regarding the ability to use regex in a bash case statement. Is this possible and if so what is the proper syntax when using regex for the pattern to match?

Thanks.
 
Old 01-31-2009, 01:20 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
The man page should be the "definitive guide" about that. I read in mine:
Code:
case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esac
    A  case command first expands word, and tries to match
    it against each pattern in turn, using the same match‐
    ing rules as for pathname expansion. (see Pathname
    Expansion below).
This tells me it does not doe regexp's, but it does do the (simpler) pathname pattern expressions. So it does the same as for example: "ls *.txt" but also a little more complex patterns like: "ls my_*-[0-9].sh". But not the entire regular expression syntax.
 
  


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
Pattern matching in BASH. ccin1492 Programming 8 12-19-2008 12:00 PM
bash: better way to delete files not matching a regex? pbhj Programming 8 10-15-2007 04:05 PM
bash script pattern matching thedude2010 Programming 9 06-02-2006 03:39 AM
Pattern matching with a "case" statement in BASH King V Programming 8 04-27-2006 05:19 PM
Pattern Matching Help in Bash script cmfarley19 Programming 1 04-07-2004 10:22 AM


All times are GMT -5. The time now is 03:37 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration