[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: rsync --delete



On Fri, Oct 16, 2020 at 11:29:34PM -0700, Will Mengarini wrote:
> debian/pts/14 bash ~ 23:25 0$a="x y z"
> debian/pts/14 bash ~ 23:25 0$echo $a
> x y z
> debian/pts/14 bash ~ 23:26 0$echo "$a" # preferred
> x y z
> debian/pts/14 bash ~ 23:26 0$# When $a is embedded, quote *outer* string:
> debian/pts/14 bash ~ 23:27 0$echo "foo $a bar"
> foo x y z bar
> debian/pts/14 bash ~ 23:27 0$

You're so close here, but you drew the wrong conclusion.

When creating an array variable that contains a list of arguments,
you want each argument to be passed separately.  That's the entire
purpose and point of the array variable.

unicorn:~$ args=(-v CFLAGS="-g -O" -q)
unicorn:~$ printf '{%s} ' "${args[@]}"; echo
{-v} {CFLAGS=-g -O} {-q} 

Use an array variable, not a string variable, to hold a list of
arguments.  Use the quoted [@] expansion to expand the array variable.

args=(... your arguments here ...)
somecmd "${args[@]}"

Any other usage is wrong, and will cause bugs eventually.  See also
<https://mywiki.wooledge.org/BashFAQ/050>.


Reply to: