LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-15-2009, 11:08 AM   #1
eguider
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 :

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

my script contains :

#!/bin/bash
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, 11:16 AM   #2
catkin
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, 08:26 PM   #3
ghostdog74
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?
Code:
for file in [a-zA-Z0-9]*.doc
do
 echo "found: $file"
done
 
  


Reply

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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:22 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
Open Source Consulting | Domain Registration