View Full Version : $1 with spaces
lolcese
March 22nd, 2006, 02:54 PM
I wrote a very small script called gr with one parameter passed from bash:
grep -nri $1 *
Works well, but if the argument contains a space, the result is wrong. I tried to call using quotes gr "aaa bbb", but the space is the problem.
Any idea about what can I do?
Thanks
colo
March 22nd, 2006, 03:02 PM
You need to quote your actual argument, somewhat like the following:
yourscript.sh "first argument" "second argument" thirdargument fouthargument
lolcese
March 22nd, 2006, 03:06 PM
You need to quote your actual argument, somewhat like the following:
yourscript.sh "first argument" "second argument" thirdargument fouthargument
Thank you for your help, but doesn work, it pass only "first" in your example
engla
March 22nd, 2006, 03:19 PM
I wrote a very small script called gr with one parameter passed from bash:
grep -nri $1 *
Quote it in the script, like so:
grep -nri "$1" *
Here is a nice link tip:
Writing robust bash scripts (http://www.davidpashley.com/articles/writing-robust-shell-scripts.html)
lolcese
March 22nd, 2006, 03:27 PM
I worked, but I have put
grep -nri "$1" *
and also "aaa bbb" in the command line.
Many thanks to all
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.