From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22355 invoked by alias); 4 Apr 2011 20:56:09 -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: 15928 Received: (qmail 29576 invoked from network); 4 Apr 2011 20:55:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at yahoo.fr does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.fr; s=s1024; t=1301950204; bh=qwZWB9tlUEVg2ihwHQPtGuH3XrIgBapEzWNAq270Beg=; h=X-Yahoo-Newman-Id:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Date:From:To:Cc:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent; b=oxjhAiVTBgMrdvQY+EtelvQfWzG1H9qS6SWuPg9MOijR2OPgvCrDBs2NfKqwvlZ9MOtrxoe6LI4r00BFFILXc2QNfXAEWN42KALV8UXw1qJSo9tZCq1odtc1zh/SUCMU9GEw8s+bwjzQaJojQQpuHAZV6f2T3puXbSv7qH6I13I= X-Yahoo-Newman-Id: 362327.66071.bm@smtp146.mail.ukl.yahoo.com X-Yahoo-SMTP: V1UR0WuswBDVD1eFhM33188Ir8ciBckz4W8ZMsAh X-YMail-OSG: VgN2sVUVM1lp5NsE2aadtvAAjTiZFHw4bF2wOVSDGBVDX4E wYwc1p8q7C_CtWQr_ckroDrzq7GT0x.WqBbUT9espNX5zQz1g6Yxkh2CQqoq 0aFx4U4ge16ejTdGR0K06Xj43FnrrmvfTtRNQIvD4CJ28J2UJyrizM5gUfja 7L8m1JsBPgPHcMoWkGNq1hYgZRA0ucq5r6P.j3pP4vDvc8TUZ6ZxYC9Vq7Tp ZUh.uH5l8cPyiRilmyPGQc4DrEU0yoZX6FIqg7yltoCkggAy9w3B01K0fW1U myzjSiW4eJ84Qf6dFhBQbJd0KSiEKtmzZ4rK_Tb0wXlsRvl8wHro9VA-- X-Yahoo-Newman-Property: ymail-3 Date: Mon, 4 Apr 2011 21:50:02 +0100 From: Stephane Chazelas To: Mikael Magnusson Cc: Zsh Users Subject: Re: is variable with variable name possible? Message-ID: <20110404205002.GD9371@yahoo.fr> Mail-Followup-To: Mikael Magnusson , Zsh Users References: <20110404140651.GA9371@yahoo.fr> <20110404162824.GB9371@yahoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) 2011-04-04 18:34:26 +0200, Mikael Magnusson: [...] > >> > eval "$somevar=\$(pwd)" > >> > or > >> > eval "$somevar=\$PWD" [...] > >> How do you feel about this? > >> : ${(P)somevar::=$PWD} > > [...] > > > > Try after > > > > sudo ln -s . '/*' > > cd '/*/*/*/*/*' > > setopt globsubst > > > > ;-) > > > > (if you're lucky, it won't crash your machine). > > Pretty sure globsubst breaks your idea too, but fine, > : ${(P)~~somevar::=$PWD} > In fact, globsubst pretty much breaks every hook function i have :P. [...] eval "$somevar=\$(pwd)" or eval "$somevar=\$PWD" are POSIX and POSIX shells have globsubst and shwordsplit on. The above will work regardless of the status of those options. In POSIX shells, you need to quote variables to prevent globsubst or shwordsplit, even in arguments to ":" because globsubst can be very very resource intensive. You can bring a machine to its knees with : ${var=foo} if $var is for instance /*/*/*/../../../*/*/*/../../../*/*/* So, you should either use instead: var=${var-foo} or : "${var=foo}" In your example, if we have to accomodate users enabling shwordsplit or globsubst (or running zsh in sh or ksh emulation), we need : "${(P)somevar::=$PWD}" But eval "$somevar=\$PWD" is more legible and more portable. -- Stephane