From: ZyX <zyx@np.by>
To: Mikael Magnusson <mikachu@gmail.com>, Zsh Users <zsh-users@zsh.org>
Subject: Re: is variable with variable name possible?
Date: Tue, 5 Apr 2011 08:10:19 +0400 [thread overview]
Message-ID: <201104050810.19865@-zyx> (raw)
In-Reply-To: <20110404205002.GD9371@yahoo.fr>
[-- Attachment #1: Type: text/plain, Size: 2230 bytes --]
Reply to message «Re: is variable with variable name possible?»,
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
>
> : "${(P)somevar::=$PWD}"
If we are talking about script, then you should use `emulate -L zsh' somewhere
at the top. This will deal with all possible weird options that are set by user.
> 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.
Somebody said that $somevar contains nothing harmful?
Original message:
> 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.
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2011-04-05 4:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-04 13:37 zzapper
2011-04-04 13:48 ` Jérémie Roquet
2011-04-04 13:51 ` Jérémie Roquet
2011-04-04 14:13 ` zzapper
2011-04-04 14:26 ` Bart Schaefer
2011-04-05 8:31 ` Bart Schaefer
2011-04-04 14:06 ` Stephane Chazelas
2011-04-04 14:25 ` Mikael Magnusson
2011-04-04 16:28 ` Stephane Chazelas
2011-04-04 16:34 ` Mikael Magnusson
2011-04-04 20:50 ` Stephane Chazelas
2011-04-04 22:32 ` Mikael Magnusson
2011-04-05 18:39 ` Stephane Chazelas
2011-04-05 2:54 ` Aaron Davies
2011-04-05 3:54 ` Phil Pennock
2011-04-05 4:04 ` ZyX
2011-04-05 4:10 ` ZyX [this message]
2011-04-04 14:33 ` Jérémie Roquet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201104050810.19865@-zyx \
--to=zyx@np.by \
--cc=mikachu@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).