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 10-28-2011, 05:23 PM   #1
mdcjsps
LQ Newbie
 
Registered: Oct 2011
Posts: 4

Rep: Reputation: Disabled
Smile passing globbing expressions as argument to bash script


I wish to shorten the 'find' command and have written my own script: ff
ff after echoing some information issues
find $1 -iname $2
where I issue the command in a terminal: ff . '*.mm'
(find all of the files that have an 'mm' extension in the current directory and below)
find . -iname '*.mm' and
find . -iname \*\.mm both work
I have tried various combinations of ' and " and \ and \\ to get this command to work

Any explanation of why this is not working would be greatly appreciated.
Thanks in advance
 
Old 10-29-2011, 01:15 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
Quote:
Chapter 8. Writing interactive scripts
Chapter 8 of the Bash Guide for Beginners covers the topic.
 
Old 10-29-2011, 03:23 AM   #3
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
You are implying that your script does not work .... in what way? Are you getting errors?
 
Old 10-29-2011, 05:04 AM   #4
mdcjsps
LQ Newbie
 
Registered: Oct 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for the link to the beginners guide. Did not find the answer I was looking for probably because my question was poorly formed.
1) when I say the script didn't work, it was because it did not find the files though they exist.
2)To hopefully clarify my question, here's what I want to do: I want to issue a command like
ff . '*.mm'
ff is a script I wrote. It has has one command in it:
find $1 -iname $2

No amount of playing with the 2md argument of the ff command will get the result that I want, which is to list all of files in the "." directory (current directory) with the "mm" extension.

The script runs (I put out some echo statements in it) but it does not list the files.

Again, thanks in advance.
 
Old 10-29-2011, 05:48 AM   #5
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
Did you try putting the second argument in quotes?

And for that matter to be on the safe side in case the first has unusual characters in it i would put that in quotes too.
 
Old 10-29-2011, 05:59 AM   #6
mdcjsps
LQ Newbie
 
Registered: Oct 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by grail View Post
Did you try putting the second argument in quotes?

And for that matter to be on the safe side in case the first has unusual characters in it i would put that in quotes too.
I have tried the following:
ff . \*\.mm
ff . "*.mm"
ff . '"*.mm"'
ff . "'*.mm'"
and have tried numerous versions of quote with the escape \
eg.
ff . "\*\*.mm"
ff . "*\.mm"
ff . '\*\.mm'
ff . '*.\mm'

and versions with " and ' with the escape
 
Old 10-29-2011, 06:09 AM   #7
mdcjsps
LQ Newbie
 
Registered: Oct 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by mdcjsps View Post
I have tried the following:
ff . \*\.mm
ff . "*.mm"
ff . '"*.mm"'
ff . "'*.mm'"
and have tried numerous versions of quote with the escape \
eg.
ff . "\*\*.mm"
ff . "*\.mm"
ff . '\*\.mm'
ff . '*.\mm'

and versions with " and ' with the escape
Have solved it.
When I issue the script: ff . \*\.mm
and the script issues
find "$1" -iname "$2"
I get the listing I was looking for.
Thanks for the help
 
  


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
Passing string as a single argument in shell script sinoob Linux - General 3 09-14-2011 04:21 AM
What is the difference between Regular Expressions and Globbing? Linux.Girl Linux - Newbie 9 08-27-2010 07:40 AM
[SOLVED] (Something like...) passing an argument to a MATLAB script Mike_V Programming 1 12-21-2009 05:04 PM
shell script, Passing string as argument? antis Programming 4 09-07-2007 02:03 AM
PHP Script argument passing error... lokee Linux - Software 5 04-24-2003 10:42 AM


All times are GMT -5. The time now is 10:19 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration