LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   passing globbing expressions as argument to bash script (https://www.linuxquestions.org/questions/linux-newbie-8/passing-globbing-expressions-as-argument-to-bash-script-910696/)

mdcjsps 10-28-2011 04:23 PM

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

bigrigdriver 10-29-2011 12:15 AM

Quote:

Chapter 8. Writing interactive scripts
Chapter 8 of the Bash Guide for Beginners covers the topic.

grail 10-29-2011 02:23 AM

You are implying that your script does not work .... in what way? Are you getting errors?

mdcjsps 10-29-2011 04:04 AM

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.

grail 10-29-2011 04:48 AM

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.

mdcjsps 10-29-2011 04:59 AM

Quote:

Originally Posted by grail (Post 4511089)
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

mdcjsps 10-29-2011 05:09 AM

Quote:

Originally Posted by mdcjsps (Post 4511096)
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


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