LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 10: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, 10:16 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
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 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


All times are GMT -5. The time now is 06:35 AM.

Main Menu
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