From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20752 invoked by alias); 13 Mar 2018 16:36:48 -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: 23238 Received: (qmail 18970 invoked by uid 1010); 13 Mar 2018 16:36:48 -0000 X-Qmail-Scanner-Diagnostics: from aurora-borealis.phear.org 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(94.242.205.164):SA:0(-1.9/5.0):. Processed in 1.362853 secs); 13 Mar 2018 16:36:48 -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=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_DKIM_INVALID,T_RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: khatar@phear.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: amavisd-new at phear.org DKIM-Filter: OpenDKIM Filter v2.10.3 aurora-borealis.phear.org 3AADF10064 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=phear.org; s=20180217; t=1520958999; bh=Ktk3khKXCcnJ1Mwb5goha0Hn3aaamBnCJAUJojY62NQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=P+iPdjJbOIYoCNwC657YTHjUKkzvY1Qeqhr+iNeS9rKkrVo4/VWt/7Hx0Ir08Qh/T LqpNVMvPozmdiANisBOTFKQhGr/sjb8uggMqCVeUzmpR1d3L5hK0m+kR2yqzEk7O35 pyJFWS7MW1ILjI2YYGJHa9flWiLRuJ3+5w7RJbUsWR0JI+KLFBgkgT03cqI0EV8/VZ 5L/LYczAST5JLM34By4rO7gQ9ZP9S6U9qdq0DYcFcO0s6YZ/Z7w8trkkUxswUpLd6t OYUnPYgy/61CnJHFM9VfgsNtjsrjJfjaUAauycIs7K1t8PJ0Z5y5hQVK/NavmwWNLV rMZSDII1/g67Q== Date: Tue, 13 Mar 2018 17:36:34 +0100 From: Marc Chantreux To: Ray Andrews Cc: zsh-users@zsh.org Subject: (some tips about variables) Re: avoid eval? Message-ID: <20180313163634.s4qvlfhdzqplxn4s@prometheus.u-strasbg.fr> References: <059f4f08-7f7f-25d8-dfeb-1653e3c8ba95@eastlink.ca> <20180311225321.shqrx7idd57ie62d@prometheus.u-strasbg.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) hello, > Is there any way to immunize my functions against $IFS trouble?  I have > functions that seem to require " $IFS=$'\n' " and others that insist on " > $IFS=' '  ". 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. also, you can make your functions more reliable by reporting when * you are using unset variables * you are setting a global variable in the functions to summarize: * use zsh options that protects you from mistakes setopt warncreateglobal nounset * 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 } slurp () { IFS=$'\n' read -d '' -A $1 } readlines () { local _; IFS=$'\n' read -d '' "$@" _ } * at least, localize your variables slurp () { local IFS=$'\n' ; read -d '' -A $1 } readlines () { local _IFS=$'\n' ; read -d '' "$@" _ } regards, marc