You are not logged in.

#1 2012-01-31 00:33:38

kriz
Member
Registered: 2009-06-29
Posts: 96

help writing a search bash function

hi
i want to make me a bash function which executes find -iname '*[foo]*'

my try

function search {
find -iname '*$1*'
}

didn't work


„Je verdinglichter die Welt, je dichter das Netz, das der Natur überworfen wurde, desto mehr beansprucht ideologisch das Denken, das jenes Netz spinnt, seinerseits Natur, Urerfahrung zu sein." Theodor W. Adorno [aus: Wozu noch Philosopie]

Offline

#2 2012-01-31 00:37:51

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: help writing a search bash function

search() {
  find -iname '*$1*'
}

Offline

#3 2012-01-31 00:43:22

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: help writing a search bash function

What about:

find -iname "*$1*" 

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#4 2012-01-31 12:00:56

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: help writing a search bash function

Use double quotes, like jasonwryan suggested.

'man bash', section QUOTING has some info on this:

       There  are  three  quoting  mechanisms:  the  escape character, single
       quotes, and double quotes.
...
       Enclosing characters in single quotes preserves the literal  value  of
       each  character  within  the  quotes.
...
       The  special  parameters  *  and @ have special meaning when in double
       quotes (see PARAMETERS below)

Offline

Board footer

Powered by FluxBB