From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28232 invoked by alias); 7 Mar 2013 19:09:00 -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: X-Seq: 17677 Received: (qmail 8997 invoked from network); 7 Mar 2013 19:08:48 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at spodhuis.org does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d201210; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=CTNc9GjQ46l9wjhxltQCL5U+HqpEpo3/6UjFIGkj020=; b=qNdvWEhoVodYYHHI3ciNobRCMQlpKPMSoYNRbBgG3cvKEB8rNXO0F/UW/ZT73hNtLNWav1oxv91shuCDWLEBuBnQpJpr24RlgxRxipfpvvl2MehXmzSDgBXY2YkaywhZAl7dAg+BRMc1rlKSig7/L5hUezBNTT5FyG0cRf5t2Tk=; Date: Thu, 7 Mar 2013 14:08:42 -0500 From: Phil Pennock To: Christopher Browne Cc: rahul , Zsh Users Subject: Re: Higher order functions in zsh (article link) Message-ID: <20130307190842.GA67680@redoubt.spodhuis.org> Mail-Followup-To: Christopher Browne , rahul , Zsh Users References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On 2013-03-07 at 11:59 -0500, Christopher Browne wrote: > cbbrowne@cbbrowne /tmp/maptest> function map { > local func_name=$1 > shift > for elem in $@; print -- $(eval $func_name "${elem}") > } > > But somewhat curiously that doesn't help :-(. Why does this code have an eval in there? It's: (1) breaking the f3 example (2) introducing a security flaw Hint: touch 'f4 `mkdir snert`' This works fine: ----------------------------8< cut here >8------------------------------ function map { local func_name=$1 shift for elem in "$@"; print -- $($func_name "${elem}") } ----------------------------8< cut here >8------------------------------ With the eval in there, with { map echo * } f3 loses the quotes and f4 just shows "f4" and creates a new sub-directory, snert. Lose the eval and things work, no new security hole. Oh, and you need to quote the $@ to "$@" if you want to preserve empty elements -- whether you do or not depends on what you're mapping across, but I tend to think "present but empty" is distinct from "not present". -Phil