Skip to main content
grammar tweaks
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

I love using the following pattern for searching in files:

grep --color=auto -iRnHr --include={*.js,*.html,} --exclude-dir={release,dev,} "span" .

I'd like, however, to have this one wrapped into a bash comandcommand like this:

findinfiles {*.js,*.html,} {release,dev,} "span"  // syntax is just a guessing

I cannot solve the problem of passing this kindthese kinds of braces into a bash function and using them with $1, $2 and so on. When I use the following:

function findinfiles() {
    echo $1, $2, $3
}

Then:

me@pc ~> findinfiles {*.js,*.html,} {release,dev,} "span"
*.js, *.html, release

OfcOf course, passing arguments to grep won't work this way. It seems that arguments are indexed but not properly grouped.

Can anyone teach me how to deal with this kindthese kinds of arguments?

I love using the following pattern for searching in files:

grep --color=auto -iRnHr --include={*.js,*.html,} --exclude-dir={release,dev,} "span" .

I'd like, however, to have this one wrapped into a bash comand like this:

findinfiles {*.js,*.html,} {release,dev,} "span"  // syntax is just a guessing

I cannot solve the problem of passing this kind of braces into a bash function and using them with $1, $2 and so on. When I use the following:

function findinfiles() {
    echo $1, $2, $3
}

Then:

me@pc ~> findinfiles {*.js,*.html,} {release,dev,} "span"
*.js, *.html, release

Ofc, passing arguments to grep won't work this way. It seems that arguments are indexed but not properly grouped.

Can anyone teach me how to deal with this kind of arguments?

I love using the following pattern for searching in files:

grep --color=auto -iRnHr --include={*.js,*.html,} --exclude-dir={release,dev,} "span" .

I'd like, however, to have this one wrapped into a bash command like this:

findinfiles {*.js,*.html,} {release,dev,} "span"  // syntax is just a guessing

I cannot solve the problem of passing these kinds of braces into a bash function and using them with $1, $2 and so on. When I use the following:

function findinfiles() {
    echo $1, $2, $3
}

Then:

me@pc ~> findinfiles {*.js,*.html,} {release,dev,} "span"
*.js, *.html, release

Of course, passing arguments to grep won't work this way. It seems that arguments are indexed but not properly grouped.

Can anyone teach me how to deal with these kinds of arguments?

edited tags
Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k
Tweeted twitter.com/#!/StackUnix/status/274136140657864704
Source Link
oleq
  • 383
  • 1
  • 3
  • 10

Bash: passing braces as arguments to bash function

I love using the following pattern for searching in files:

grep --color=auto -iRnHr --include={*.js,*.html,} --exclude-dir={release,dev,} "span" .

I'd like, however, to have this one wrapped into a bash comand like this:

findinfiles {*.js,*.html,} {release,dev,} "span"  // syntax is just a guessing

I cannot solve the problem of passing this kind of braces into a bash function and using them with $1, $2 and so on. When I use the following:

function findinfiles() {
    echo $1, $2, $3
}

Then:

me@pc ~> findinfiles {*.js,*.html,} {release,dev,} "span"
*.js, *.html, release

Ofc, passing arguments to grep won't work this way. It seems that arguments are indexed but not properly grouped.

Can anyone teach me how to deal with this kind of arguments?