Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Global And Local Variables in zsh Functions



On Sun, Aug 9, 2015 at 12:44 AM, Georg Wittig <nc-wittigge@xxxxxxxxxxxxx> wrote:
> Hi,
>
> I'm writing a zsh script that's constructing a rather complex rsync
> command. One part of the script is constructing  a list of exclude
> commands for rsync. For this I use a global variable EXC. It is built
> in the following way
>
> EXC=''
> function my_f1 () {
>   EXC+=" --exclude='$1'";
> }
> my_f1 /tmp
> my_f1 /opt/windows7
> echo ">>>$EXC<<<"

In addition to the other replies, you'll also want to change EXC to be an array,
EXC=()
my_f1() {
  EXC+=( --exclude=$1 )
}
(note lack of quoting is intentional)

Otherwise, you'll have a bad time trying to actually run the command.

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author