From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3867 invoked by alias); 5 Apr 2011 04:11:08 -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: 15933 Received: (qmail 12764 invoked from network); 5 Apr 2011 04:11:07 -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.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.161.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:reply-to:to:subject:date:user-agent :references:in-reply-to:mime-version:content-type :content-transfer-encoding:message-id; bh=tXN0EmQUgkMwDjaA2Tzv6u755X/VNR+JnoZz+aApVlU=; b=w4TYBzQPK1+BaKgsS0Pf/gfxdVkaFuuPhtA1sQ4GTJAgFJTTpacQE1E6YtLpmUx6Xx kmjNo2sQ2CYkUNzMyybJ9DgXYIRiGjXuExAg+DZpcO1XK3lIHqo18Cxu7XFWufCjwKyz NARgOk1QqDPVau/undZ/DAASlJScC/wnYwAKc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; b=Ncz/HhT/DT5P3H2CEAsMPacSks5QBtsHa4bidACw2/+f5uz2IABWc0bNybUJ9DTvhr /v0AwFtPg97JtAAgm7yvk7KMKs+Q2EtO3BKYPZzCLbeHE0Z2sc/ATnpAnJeyQBq1JugH ngeCa29nfU8S3RikzBRYM47bwMIBH3H5lerAQ= From: ZyX Reply-To: zyx.vim@gmail.com To: Mikael Magnusson , Zsh Users Subject: Re: is variable with variable name possible? Date: Tue, 5 Apr 2011 08:04:59 +0400 User-Agent: KMail/1.13.5 (Linux/2.6.36-zen1; KDE/4.5.5; x86_64; ; ) References: <20110404205002.GD9371@yahoo.fr> In-Reply-To: <20110404205002.GD9371@yahoo.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1550318.UrhREW07Mr"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201104050804.59439@-zyx> --nextPart1550318.UrhREW07Mr Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Reply to message =ABRe: is variable with variable name possible?=BB,=20 sent 00:50:02 05 April 2011, Tuesday by Stephane Chazelas: > In your example, if we have to accomodate users enabling > shwordsplit or globsubst (or running zsh in sh or ksh > emulation), we need >=20 > : "${(P)somevar::=3D$PWD}" If we are talking about script, then you should use `emulate -L zsh' somewh= ere=20 at the top. This will deal with all possible weird options that are set by = user. > eval "$somevar=3D\$(pwd)" > or > eval "$somevar=3D\$PWD" >=20 > are POSIX and POSIX shells have globsubst and shwordsplit on. > The above will work regardless of the status of those options. Somebody said that $somevar contains nothing harmful? Original message: > 2011-04-04 18:34:26 +0200, Mikael Magnusson: > [...] >=20 > > >> > eval "$somevar=3D\$(pwd)" > > >> > or > > >> > eval "$somevar=3D\$PWD" >=20 > [...] >=20 > > >> How do you feel about this? > > >>=20 > > >> : ${(P)somevar::=3D$PWD} > > >=20 > > > [...] > > >=20 > > > Try after > > >=20 > > > sudo ln -s . '/*' > > > cd '/*/*/*/*/*' > > > setopt globsubst > > >=20 > > > ;-) > > >=20 > > > (if you're lucky, it won't crash your machine). > >=20 > > Pretty sure globsubst breaks your idea too, but fine, > >=20 > > : ${(P)~~somevar::=3D$PWD} > >=20 > > In fact, globsubst pretty much breaks every hook function i have :P. >=20 > [...] >=20 > eval "$somevar=3D\$(pwd)" > or > eval "$somevar=3D\$PWD" >=20 > are POSIX and POSIX shells have globsubst and shwordsplit on. > The above will work regardless of the status of those options. >=20 > 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. >=20 > You can bring a machine to its knees with >=20 > : ${var=3Dfoo} >=20 > if $var is for instance /*/*/*/../../../*/*/*/../../../*/*/* >=20 > So, you should either use instead: >=20 > var=3D${var-foo} > or >=20 > : "${var=3Dfoo}" >=20 > In your example, if we have to accomodate users enabling > shwordsplit or globsubst (or running zsh in sh or ksh > emulation), we need >=20 > : "${(P)somevar::=3D$PWD}" >=20 > But >=20 > eval "$somevar=3D\$PWD" >=20 > is more legible and more portable. --nextPart1550318.UrhREW07Mr Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iEYEABECAAYFAk2alOsACgkQkOgHluiXxU/slwCgi1eXtRnS3GwyV3BxoSAnEQle mtQAmwW5mIAW1Tr169Ffbr8rEopJzMXf =o9nw -----END PGP SIGNATURE----- --nextPart1550318.UrhREW07Mr--