LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   'Find' command not behaving in a script (http://www.linuxquestions.org/questions/linux-software-2/find-command-not-behaving-in-a-script-864867/)

devmoc 02-24-2011 07:19 PM

'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.

crts 02-24-2011 07:24 PM

Quote:

Originally Posted by devmoc (Post 4270271)
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*"


devmoc 02-25-2011 03:36 AM

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*'


All times are GMT -5. The time now is 11:43 PM.