Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-15-2009, 10:08 AM   #1
LQ Newbie
Registered: Dec 2009
Posts: 1

Rep: Reputation: 0
Cool execute script shell with regex as argument

hi all

I want to create a script shell that accept a regular expression as argument.

exemple :

./ "[a-zA-Z0-9]*\.doc"

my script contains :

find ./ -regextype posix-extended -regex "\./$2" -type f"

but the problem is that (* and {x,y}...) in regular expression is interpreted diferently :s

can you help me plz.
Old 12-15-2009, 10:16 AM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Four ideas.

Firstly bash interprets \ characters in double-quoted strings so better change "[a-zA-Z0-9]*\.doc" to '[a-zA-Z0-9]*\.doc' on the command line so the script receives the string verbatim.

Secondly "[a-zA-Z0-9]*\.doc" is the only command line argument passed to the script so it is $1, not $2 as used in the find command.

Thirdly the same problem as the first in "\./$2". Solution to use "\\./$2" or '\./'"$2".

Finally there is an unbalanced trailing double quote in find ./ -regextype posix-extended -regex "\./$2" -type f"
Old 12-15-2009, 07:26 PM   #3
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
any reason why you want to use regex with find?
for file in [a-zA-Z0-9]*.doc
 echo "found: $file"


argument, as, regex

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
help with execute mulitple shell script within shell script ufmale Programming 6 09-13-2008 12:21 AM
shell script: can getopt process more than one argument per option? BrianK Programming 2 12-13-2007 05:11 PM
shell script, Passing string as argument? antis Programming 4 09-07-2007 01:03 AM
performing regex on shell script variable? ocicat Programming 3 07-17-2007 02:10 PM
PHP pass argument to shell script monzter Programming 2 08-14-2004 06:16 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:29 PM.

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