From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23507 invoked by alias); 8 Nov 2015 17:07:58 -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: 20934 Received: (qmail 11337 invoked from network); 8 Nov 2015 17:07:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_HDRS_LCASE, T_MANY_HDRS_LCASE autolearn=ham autolearn_force=no version=3.4.0 X-Authority-Analysis: v=2.1 cv=T/C1EZ6Q c=1 sm=1 tr=0 a=Rb7dudWe+J2gL+/7yVpO1Q==:117 a=Rb7dudWe+J2gL+/7yVpO1Q==:17 a=IkcTkHD0fZMA:10 a=QJyqODk3I1ayXctBcL4A:9 a=g7oOLr6kEvnFr1-6:21 a=yz3Rjs9Snfu84XTu:21 a=QEXdDO2ut3YA:10 Message-id: <563F8168.5080006@eastlink.ca> Date: Sun, 08 Nov 2015 09:07:52 -0800 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-version: 1.0 To: Zsh Users Subject: saved from prince of eval Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 7bit I'm trying to get some mileage out of the '(e)' flag, but it frustrates me: 1: $ foo="${(e)${array}[${top}, ${bottom}]}" foo contains the name of the array, nothing more. The doc says that these things can be nested. I tried a few things on one line with no luck. If I insert the literal name of the array in place of "${array}" everything is fine. But this works: 2: $ bar='\$${array}[${top}, ${bottom}]' 3: $ foo="${(e)$(print -R "${(e)${bar}}")}" I'm not sure how to interpret it tho. Is 'print' doing the work here, or is print a bystander as a nested use of '(e)' works? The expansion of 'bar' with it's single quoted string in '3' has a sort of linearity to it--you'd think that '1' would work, but it refuses to expand all three parameters whereas in '3' the expansion handles all three parameters in a 'dumb' but actually far more intuitive and helpful way--it just does it. I'd like to understand this better, it could be a case of some tiny syntactic error. Why does '1' not work? What's really going on in '3'? In any case, it replaces the evil eval which is very nice: $ foo='stranger' $ bar='echo howdy $foo' $ eval $bar howdy stranger << Sure ... $ eval baz=$bar; echo $baz zsh: command not found: howdy << Ferkrissakes echo howdy $foo $ baz=${(e)bar}; echo $baz << Tranquility echo howdy stranger ... so '(e)' is our friend. We should be warned from mother's milk not to use eval, and I have been warned, but, nuts, I didn't realize that there was a safe solution.