BASH function not escaping control characters
Posted
by
ehime
on Super User
See other posts from Super User
or by ehime
Published on 2012-08-31T19:14:27Z
Indexed on
2012/08/31
21:40 UTC
Read the original article
Hit count: 366
Hey guys I have a function that I'm using to find stuff, but unfortunately anytime I pass it a control character ($intVal
or testing :
etc) it chokes. I was wondering what the fix was?
I can understand that using $
or %
or :
etc in grep without escaping causes this issue, but since I'm passing it in by reference I'm not sure how to escape it...
Anyway, here's the code.
function ffind()
{
if [ $1 ] ; then
find -type f | grep -ir '$1' * | grep -v '.svn'
else
echo "'$1' is not a valid resource"
fi
}
Example(s):
$ ffind $intVal
'' is not a valid resource
$ ffind "testing :"
bash: [: testing: unary operator expected
'testing :' is not a valid resource
© Super User or respective owner