From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28843 invoked from network); 20 Jan 2021 16:17:19 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Jan 2021 16:17:19 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1611159439; b=TiJm3MIinvmaCLyGD8fPRRjULljaaEsU3HmBArBq35ndeFIp4YggU1eE3OoxSaIVI+YHbrGyYp vnCndU7DtVD4sCcwH2vwCEmLgtIdmZB/2mjWKRnEjuuTrNB7J/ZnG0uH3JlltjYCCA3AjM6hIs XoB63dYC7a5S12UTSqWwtc8d+BiBR8NMjE1vCUejDnGo1bxIO6E9y9vj+red2wLR30EATNppr+ ytiyTNKmYBKyiLrnH+skBAfLd4IFycDETAkkwlZKMC6ogEcutC7zSqyyxGwc5LMQf03hmsmjM6 AGjSvQwXKXU3f4j3Z4eC/hnfgoA4MLNW0ph2JSv6h2aeoQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-qk1-f182.google.com) smtp.remote-ip=209.85.222.182; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1611159439; bh=mbfjDJWsZzHZGuyrccDsziOJ2Z/Hp75kJVbDQ7M0xhk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:MIME-Version:Date:Message-ID:Subject:From:To: DKIM-Signature:DKIM-Signature; b=qdyKfLCfcsJEWnp9IrGNScGZJHXEJaRF6+UU7Z3Uqnn103DQCQTBvxpmz6U5j2XMJcYbiHojCG INHjRYWOJqOWJuGfr7uBbCYDbO//ZPca47gtXhCmTqejh0TVWGGe6irSL0xOrS+seq/RoBNicU 7eQqW7n9pzC2UvlNs6GbjHan9QPExN1Tqtp2MkZJjmZd6zv0m/lKxC/bJPq3gPaXgUr9jUt2Au N2v9s5CSq2Xkn4S2xTDuaY/z6PwSZ2PFH2Hv7wgzE3q4yfnhD49awTM6PMnbQm0i7lSjnG0rMc Qj1FyrgkZgxV3xx4fC1MC5qEHbEouGLJ89et6oBF4TX1pg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:MIME-Version:Date: Message-ID:Subject:From:To:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=Y0Dk1eBWQNn7GPSmBXk1oo1dlgq5N4xPZUOV0w6fY60=; b=DvTua6KmRwlsxfS7zzlCYQNJ5e tz9tfpIix3/aizxyEq1TArZRnRXA5YJOZCPYnYrdJy47carIJ6ciKjbrpjIpWFW+vkG5gEl0bYYu/ Tu6Ts1z3OCzBHRJrLtO/ohrPJ08F1SmIn1thXtMzu+SixTpFsbA24PPO40UmKXc3Epe+AV9WBaU1P L4lGedz/XFoFSuVz3CrnM8U70L7FOhorI8w6rjGFbJYQ6whkAlHtAdqtzpqhXQbUryEBBCGKiGlNX y1QLTI72dI3TfQoZgqeLV0qkYAULXlxkwHaiwaLmuf9eHqaJ0hjG3S01Ob3EwYlWyG6f8ME8pYt84 5Qo9W9Yg==; Received: from authenticated user by zero.zsh.org with local id 1l2GAW-000EHQ-MD; Wed, 20 Jan 2021 16:17:16 +0000 Authentication-Results: zsh.org; iprev=pass (mail-qk1-f182.google.com) smtp.remote-ip=209.85.222.182; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-qk1-f182.google.com ([209.85.222.182]:38056) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1l2GAE-000E85-9p; Wed, 20 Jan 2021 16:16:59 +0000 Received: by mail-qk1-f182.google.com with SMTP id d85so1673446qkg.5 for ; Wed, 20 Jan 2021 08:16:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=Y0Dk1eBWQNn7GPSmBXk1oo1dlgq5N4xPZUOV0w6fY60=; b=crLij39pcuc9YRc8H0uJvtl+Ytc6EDYt5ex9mWRhKbEs3Ixc3DWL2CdeYfmZvUH07W DH/SqgiLvwMKN/IEoFDlkrrVhidu2FX9YdBhK3PSbCR1E7yRRZ13pkJEOaeGggFNPkJb +dCFcnakWySVflpiH/0Ie4KDidQ5lbl9AsPDF6Qnus4Nx0fPupogQjYxbZbv/CBLtNXz QTBIdrJETUDOZGC6SoCSf9Y2IOkEJikwsr9cf/m1zvCrPAvYk2T43jGH/FOgTshiKgnq SxSApDsCyxRniNgooT01CNaVzQf6oQTUr8sog6xe0oj3XCshLOJbdpqwzEt8RxP8v1Gd LzGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=Y0Dk1eBWQNn7GPSmBXk1oo1dlgq5N4xPZUOV0w6fY60=; b=lTyqPNhKhYvjPjVUFgxqhvJMbo+DP+JEqGLZJPVmnOw6VHT329C6284WK8sHjCVWZk MoqIvfY3xz4o3YcM8MOF17cFwT6iVN1e+SN56oiG6tbEQxTgJNwvgmmMBmcPN1zKtKYe x+F6ybe5emd3D5Svec8GxR6I6WaoytM0+ete3nudVVHZc6sjRKFIH2oZczfxuxFxt7W6 jVhMJU4xaEWlHO3A2uBD797742gdMxJxgZMnzsQLcB96rVp0EcGxrlL7mwynYmqAeSwV aD/OOhxXbP/LVNGQpD3sSL4oMY8yiXiLKRnS4j+t1t/h+WUmqPZOGPVXQ8xZjNJBkgoi Stnw== X-Gm-Message-State: AOAM532zLdGaA/jhHvxNXU6n9POIPy4RB82iPa/+xPAEzm6Fycyb7sN7 MmsmewAcppKIoRe2UlfuVQ+ZVM2FA68bFA== X-Google-Smtp-Source: ABdhPJxn7oL7Nycyn8CLoX4juIf0FAzk5nsdNqgvYCp5LCTyyJA0kJj6ztjt1nJtu3KVR2MrrawkSg== X-Received: by 2002:a37:a24a:: with SMTP id l71mr10291757qke.161.1611159417104; Wed, 20 Jan 2021 08:16:57 -0800 (PST) Received: from ?IPv6:2804:14c:4783:8889:cc86:e5d3:62c4:635d? ([2804:14c:4783:8889:cc86:e5d3:62c4:635d]) by smtp.gmail.com with ESMTPSA id y26sm1501301qth.53.2021.01.20.08.16.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Jan 2021 08:16:56 -0800 (PST) To: zsh-workers@zsh.org From: jamil bio Subject: zsh adds empty string to local parameter when += is used Message-ID: Date: Wed, 20 Jan 2021 13:16:54 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------74EF5385270D56979D2D27A6" Content-Language: en-US X-Seq: 47850 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: This is a multi-part message in MIME format. --------------74EF5385270D56979D2D27A6 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hello good people, It seems there is a bug which I will describe below. I checked with usenet comp.unix.shell people and they said that is strange behavior. I am using Z-shell 5.8. The problem is when I add elements to an array with += inside a function, an empty element is generated. The empty element is added only if I set array $files as local. The following is an example code. #!/bin/zsh #!/bin/bash func() {     local REPLY  files     #unset files     for REPLY in file1 file2 file3     do         files+=( "$REPLY" )         echo "${#files[@]} -- ${files[@]}"     done } func If I set $files to local but unset it before the loop, the empty element is not added. Running the script with zsh returns: 2 --  file1 3 --  file1 file2 4 --  file1 file2 file3 While if we run the code with bash: 1 -- file1 2 -- file1 file2 3 -- file1 file2 file3 I was actually using a while read loop to read filenames, but the problem also occurs when I use the for loop. So the workaround suggested is to set $files as local and then later define files=( ) which will prevent empty element being added somehow. Thanks for all your efforts in making zsh so great! --------------74EF5385270D56979D2D27A6 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hello good people,

It seems there is a bug which I will describe below.
I checked with usenet comp.unix.shell people and they said that is strange behavior.

I am using Z-shell 5.8. The problem is when I add elements to an array with += inside a function, an empty element is generated. The empty element is added only if I set array $files as local.

The following is an example code.


#!/bin/zsh
#!/bin/bash

func()
{
    local REPLY  files

    #unset files
    for REPLY in file1 file2 file3
    do
        files+=( "$REPLY" )
        echo "${#files[@]} -- ${files[@]}"
    done
}

func


If I set $files to local but unset it before the loop, the empty element is not added. Running the script with zsh returns:


2 --  file1
3 --  file1 file2
4 --  file1 file2 file3


While if we run the code with bash:


1 -- file1
2 -- file1 file2
3 -- file1 file2 file3


I was actually using a while read loop to read filenames, but the problem also occurs when I use the for loop. 

So the workaround suggested is to set $files as local and then later define files=( ) which will prevent empty element being added somehow.

Thanks for all your efforts in making zsh so great!
--------------74EF5385270D56979D2D27A6--