On Wed, Jun 23, 2010 at 5:43 PM, Chris F.A. Johnson <ch...@cfajohnson.com> wrote: > On Wed, 23 Jun 2010, Peng Yu wrote: > >> Hi, >> >> According to man bash, I thought that $@ instead of $* can help me >> pass a string with space as a parameter. But it is not. Would you >> please show me how to print 'b c' as a single argument in the >> following code? > > Always quote variable references unless you have a good reason not > to. > >> #!/usr/bin/env bash >> >> function f { >> #for i in $*; >> for i in $@; >> do >> echo $i >> done >> } > > for i in "$@" ## note the quotes > do > echo "$i" ## better is: printf "%s\n" "$i" > done
Why printf is better than echo? Is this because printf is more robust than echo? -- Regards, Peng