From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28815 invoked by alias); 13 Mar 2018 17:50:25 -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: 23239 Received: (qmail 2172 invoked by uid 1010); 13 Mar 2018 17:50:25 -0000 X-Qmail-Scanner-Diagnostics: from mta01.eastlink.ca by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(24.224.136.30):SA:0(-2.6/5.0):. Processed in 1.93283 secs); 13 Mar 2018 17:50:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: rayandrews@eastlink.ca X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset=utf-8; format=flowed X-Authority-Analysis: v=2.3 cv=OKgJIxSB c=1 sm=1 tr=0 a=RnRVsdTsRxS/hkU0yKjOWA==:117 a=RnRVsdTsRxS/hkU0yKjOWA==:17 a=IkcTkHD0fZMA:10 a=WTFtxDHCpEBQW8EwGqcA:9 a=QEXdDO2ut3YA:10 X-EL-IP-NOAUTH: 24.207.101.9 Subject: Re: (some tips about variables) Re: avoid eval? To: zsh-users@zsh.org References: <059f4f08-7f7f-25d8-dfeb-1653e3c8ba95@eastlink.ca> <20180311225321.shqrx7idd57ie62d@prometheus.u-strasbg.fr> <20180313163634.s4qvlfhdzqplxn4s@prometheus.u-strasbg.fr> From: Ray Andrews Message-id: <32661718-eaa2-a270-9b88-69156f7ddfe6@eastlink.ca> Date: Tue, 13 Mar 2018 10:50:17 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-reply-to: <20180313163634.s4qvlfhdzqplxn4s@prometheus.u-strasbg.fr> Content-language: en-CA On 13/03/18 09:36 AM, Marc Chantreux wrote: > you should be carreful to reduce the scope of the change of such an > important variable. more generally, you should localize every variables > of the functions using local. > Right, as Eric also suggested. > setopt warncreateglobal nounset That's an entirely new idea, I'll study it. > * keep the IFS change as tight as possible by setting it for only one > read. exemples > > getent passwd | > while {IFS=: read login _ uid gid gecos home shell } { > [[ $shell == *zsh* ]] && print $login is cool > } > Well, it it can be *that* local, just for one loop, then that makes things much simpler. Still there are mysteries: function test () { local IFS=$'\n' echo $path[2] tty=( `stty size` )         # Grab the size of the terminal. echo $tty echo $tty[1] local IFS=' ' echo $path[2] tty=( `stty size` )         # Grab the size of the terminal. echo $tty echo $tty[1] } $ . ./test; test /aWorking/Zsh/System 52 80 52 80 /aWorking/Zsh/System 52 80 52 ... $path is space-separated, yet it is 'immune' to IFS issues. Array $tty, it is not immune to IFS.  I suspect that's because maybe $path is not an array, and it would appear that IFS only applies to arrays (?) but if so, how does one tell one from the other?  It seems counter intuitive that "$tty[1]" and "$tty" could mean the same thing in any situation.  Splitting issues seem the one thing that is always hard to get right, there seem to be dozens of variations on the theme.