From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22729 invoked by alias); 18 Jan 2017 18:53:37 -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: 22398 Received: (qmail 11215 invoked from network); 18 Jan 2017 18:53:37 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-6.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(80.0.253.70):SA:0(-1.2/5.0):. Processed in 3.25771 secs); 18 Jan 2017 18:53:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _smtprelay.virginmedia.com designates 80.0.253.70 as permitted sender) X-Originating-IP: [86.21.219.59] X-Spam: 0 X-Authority: v=2.1 cv=H94muLsi c=1 sm=1 tr=0 a=utowdAHh8RITBM/6U1BPxA==:117 a=utowdAHh8RITBM/6U1BPxA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=MWUjAzoEKyAA:10 a=Cza1W6vS-jnb9EET2msA:9 a=CjuIK1q_8ugA:10 Date: Wed, 18 Jan 2017 18:46:23 +0000 From: Peter Stephenson To: Zsh Users Subject: Re: this should be easy variable expansion including globs. Message-ID: <20170118184623.3bf91c52@ntlworld.com> In-Reply-To: <52be7a1a-2da8-a4b6-905a-3eea694763c3@eastlink.ca> References: <52be7a1a-2da8-a4b6-905a-3eea694763c3@eastlink.ca> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 18 Jan 2017 08:13:54 -0800 Ray Andrews wrote: > $ var1=var1 > $ var2=var2 > $ var3=var3 > $ var99=var99 > $ for f ($var*) echo $f I'm going to regret this, but... The right way of doing this is to use an array. It's very similar to what you've got except you refer to $var[1] rather than $var1. That index means the shell knows roughly what you've got on your mind from the start. The following syntax may look too good to be true, but does work... var=(var{1..99}) This is equivalent to typeset -a var var[1]=var1 var[2]=var2 ... The first line is there to ensure var is an array. This is a useful example as it shows that the array grows as you need it to. Now the simple "echo" you've got above can be done as print -lr -- $var The -l prints one entry per line. The -r stops any clever expansions so you get exactly what's in the array. For most operations, you probably need more control over what you're doing with entries. Depending how complicated it gets, your main choices are the following. Process every non-empty array entry, regardless of number: for elt in $var; do # $elt in turn refers to elements of the array print -r -- $elt done Process every entry whether it's empty or not --- there's no distinction between the two with the values above, it's just a bit of arcanery in case you need it. for elt in "${var[@]}"; do print -r -- $elt done Loop over all 99 elements of... well, anything, but in this case that array: integer i for (( i = 1; i <= 99; i++ )); do print -r -- $var[i] done If you nonetheless still want to do some completely different, someone else will no doubt be along in a minute for the usual loooooooong argument. pws