LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash Function Problem (https://www.linuxquestions.org/questions/linux-software-2/bash-function-problem-841268/)

Gary Baker 10-29-2010 06:52 PM

Bash Function Problem
 
This is my second post for Bash Function Problem. Thanks to all who help!


I have taken into count spacing of functions as a reason for not working. Can you get this function to work on your machine?

quickfind () { find . -maxdepth 2 -iname "*$1*" }

It does not print the retired output but find . -maxdepth 2 -iname "*$1*" does work. What is wrong?

I have gotten both to work thanks to all who helped

Gary

quickfind () { find . -maxdepth 2 -iname "*$1*" ; }

If I run this from the commandline I don't get an error but no output?
I am not running this inside a script but from the commandline.

I want to be able to run any function () from the commandline.

Thanks to all who helped I got it to work!

I have more functions that I can't get to work?

tt () { tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> " }

Thanks to all who helped I got it to work!

GrapefruiTgirl 10-29-2010 07:05 PM

Hi there,

You haven't said what evidence you have that it doesn't work, so it's hard to tell precisely what the problem is, but I have a guess or two.. The function works fine for me.

Are you running this just in the shell, or as part of a script? In either/both cases, is the working directory the same? If not, then the find command will be looking in a different "." directory.

What about the $1 ? If this is part of a script, then $1 is going to be the positional parameters that were passed to the script itself. Inside the function, it is a different $1 because functions have their own set of positional parameters. So, are you passing the filename to the function, if it's part of a script?


All times are GMT -5. The time now is 05:57 PM.