From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8992 invoked by alias); 5 Apr 2011 07:45:01 -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: 15935 Received: (qmail 7531 invoked from network); 5 Apr 2011 07:44:50 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <110404072617.ZM9904@torch.brasslantern.com> Date: Mon, 04 Apr 2011 07:26:17 -0700 In-reply-to: Comments: In reply to ( Text in unknown character set UTF-8 not shown ) "Re: is variable with variable name possible?" (Apr 4, 3:51pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: is variable with variable name possible? MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Apr 4, 3:51pm, Jeremie Roquet wrote: } Subject: Re: is variable with variable name possible? } } 2011/4/4 Jeremie Roquet : } > 2011/4/4 zzapper : } >> somevar=$(pwd) } >> } >> but I want somevar to be a variable name } > } > $ eval "$somevar=$(pwd)" } } Actually, the quotes aren't even needed: } } $ eval $somevar=$(pwd) If $(pwd) has spaces in the directory name, this is going to fail. So you do need quotes, but a different kind: eval $somevar='$(pwd)' For scalars (but not array assignments) you can also do typeset -g $somevar=$(pwd) You can also use ${somevar::=$(pwd)} anywhere that you'd reference the value of $somevar, including the no-op command: : ${somevar::=$(pwd)} That also works for array assignments if you explicitly split: : ${(As:/:)somevar::=$(pwd)} print -l $somevar Note though that here the stuff after the = is joined with the first character of $IFS before being split, so to copy one array to another you have to be careful. Also note that without the (A) the split is applied to the expansion after the assignment.