From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id cfa019e8 for ; Sun, 31 Mar 2019 09:11:00 +0000 (UTC) Received: (qmail 17826 invoked by alias); 31 Mar 2019 09:10:43 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23893 Received: (qmail 20806 invoked by uid 1010); 31 Mar 2019 09:10:43 -0000 X-Qmail-Scanner-Diagnostics: from 195.159.176.226 by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.1/25398. spamassassin: 3.4.2. Clear:RC:0(195.159.176.226):SA:0(-0.9/5.0):. Processed in 2.280654 secs); 31 Mar 2019 09:10:43 -0000 X-Envelope-From: gcszu-zsh-users@m.gmane.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at m.gmane.org does not designate permitted sender hosts) X-Injected-Via-Gmane: http://gmane.org/ To: zsh-users@zsh.org From: Anssi Saari Subject: Confused about splitting Date: Sun, 31 Mar 2019 12:06:16 +0300 Organization: An impatient and LOUD arachnid Message-ID: Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cancel-Lock: sha1:4vjDPzPl/oApSiMH9YBxqQtxt+U= I have a simple script which uses awk to assign and split a line from a file to a zsh array. Simplified, just this: foofunc () { if [[ $# -ge 1 ]] then if=$1 else if=eno1 fi first=(`awk /$if/ /proc/net/dev`) echo $first echo length of first is $#first } Obvious and works, it prints out currently with parameter eno1 this: eno1: 44977581223 33469291 0 139 0 0 0 57718 12574512832 21508919 0 0 0 0 0 0 length of first is 17 /proc/net/dev currently contains Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed lo: 990081491 293912 0 0 0 0 0 0 990081491 293912 0 0 0 0 0 0 eno1: 44978021588 33472121 0 139 0 0 0 57964 12575022205 21512486 0 0 0 0 0 0 But wanting to not call awk I ran into trouble. If I set shwordsplit, no problem: foofunc2 () { if [[ $# -ge 1 ]] then if=$1 else if=eno1 fi setopt shwordsplit while read g do if [[ $g =~ $if ]] then first=($g) break fi done < /proc/net/dev echo $first echo length of first is $#first } But what if I don't want to set shwordsplit? I came up with foofunc3 () { if [[ $# -ge 1 ]] then if=$1 else if=eno1 fi while read g do if [[ $g =~ $if ]] then first=${=g} break fi done < /proc/net/dev echo $first echo length of first is $#first } But this splits each character into an array element. I don't understand this behavior at all. As I understand it, = in the assignment to $first is supposed to turn shwordsplit on temporarily but it really doesn't seem to. IFS is not set so field separator should be default, meaning whitespace. This is with zsh 5.3.1 on Debian.