LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-24-2011, 06:19 PM   #1
devmoc
Member
 
Registered: Sep 2005
Posts: 38

Rep: Reputation: 15
'Find' command not behaving in a script


I'm trying to make an extremely simple script named 'findm' in my /usr/local/bin that looks like this:

Code:
#!/bin/bash
find -mindepth 1 -iname '*$1*'
As you can see, I want to be able to run 'findm some_argument' while in a shell in any directory.

The problem I'm having is that this script only works when I'm in my top most home directory. Any directory lower than that and the script returns no results. Any help would be appreciated. Thanks.
 
Old 02-24-2011, 06:24 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by devmoc View Post
I'm trying to make an extremely simple script named 'findm' in my /usr/local/bin that looks like this:

Code:
#!/bin/bash
find -mindepth 1 -iname '*$1*'
As you can see, I want to be able to run 'findm some_argument' while in a shell in any directory.

The problem I'm having is that this script only works when I'm in my top most home directory. Any directory lower than that and the script returns no results. Any help would be appreciated. Thanks.
Hi,

I am wondering why it works at all. Since you want the parameter to expand you should use "double-quotes" instead of single quotes.
Code:
#!/bin/bash
find -mindepth 1 -iname "*$1*"
 
Old 02-25-2011, 02:36 AM   #3
devmoc
Member
 
Registered: Sep 2005
Posts: 38

Original Poster
Rep: Reputation: 15
Thanks very much. That small oversight makes it work perfectly. Regarding single quotes, that is how I always executed it as a straight command in the shell.
Code:
find -mindepth 1 -iname '*something*'
 
  


Reply

Tags
bash, bin, find, script


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
PIPE find results to tar not behaving as expected. a1danel Linux - Newbie 4 01-15-2011 01:50 PM
Applying a script to all the files of the find command flamingo_l Programming 39 10-26-2010 02:48 AM
Bash script with find command dexznrl Programming 6 08-10-2009 12:52 PM
How to find out what is causing command not found in script debicool Linux - Newbie 1 03-14-2009 09:56 AM
problem with find command in script cojo Linux - Software 3 05-26-2004 10:28 AM


All times are GMT -5. The time now is 07:24 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