0

Trying to learn a little of bash scripting and I end up using the 'grep --color -r -n -i SEARCH .' command a lot, so I figured I'd script that. Problem is that I can't seem to pass my search term to grep correctly.

I've managed to get it to work when I pass only a single term in, so that if I enter 'search qwerty' it will perform 'grep --color -r -n -i qwerty .', but I can't get it to work if I pass in multiple terms. I would do this normally using 'grep --color -r -n -i 'qwe rty' .', however when I try this it searches for ''qwe' in rty'.

I'm not sure if I'm explaining this will so I'll post the relevant parts of the script xD

SEARCH="$*"
grep --color -r -n -i ${SEARCH} $PWD

I've tried this with SEARCH="'$*'" (which stops it working at all) and grep --color -r -n -i \'${SEARCH}\' $PWD which searches for 'qwe in rty', which is obviously not what I'm looking for.

Hope any of this makes sense ^.^

0

Try this:

grep --color -r -n -i "${SEARCH}" $PWD

It will search for "qwe rty" as one, not as "qwe" or "rty"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.