From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15622 invoked by alias); 19 Sep 2011 21:15:42 -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: 16387 Received: (qmail 16276 invoked from network); 19 Sep 2011 21:15:40 -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 autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at benizi.com does not designate permitted sender hosts) Date: Mon, 19 Sep 2011 17:15:10 -0400 (EDT) From: "Benjamin R. Haskell" To: david sowerby cc: "zsh-users@zsh.org" Subject: Re: variable/array element question In-Reply-To: <1316463747.16563.YahooMailNeo@web36607.mail.mud.yahoo.com> Message-ID: References: <1316463747.16563.YahooMailNeo@web36607.mail.mud.yahoo.com> User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="-1463810530-1263456510-1316466934=:10525" ---1463810530-1263456510-1316466934=:10525 Content-Type: TEXT/PLAIN; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT On Mon, 19 Sep 2011, david sowerby wrote: > I did array=( $(ls -l ) ) > print $array  > > and got an error  Hmmmm...... > did print ${array[2,9]} and got the expected result: elements 2-9 > so zsh didn't like the first element > Experimenting I did > > ls -l | while read one two three four etc ; do print $one $two $three ; done > same error > > So after using zsh for 2 years , I've just discovered that it doesn't > like variables to start with '-' . > Obviously I can use Awk for this example, but I was curious as to why > this is? It's not that it "doesn't like" them... ;-) Parameter expansion happens before the command is executed. The contents of the array are being interpreted as flags to the 'print' builtin. E.g. ## -l makes `print` print each thing on a separate line $ array=( -l a b c ) $ print $array a b c $ print -l a b c a b c $ array=( -what- this is ridiculous ) $ print $array zsh: bad option -w You can get around it with `print` via the '--' (stop processing) argument (which you can shorten to a single '-'): $ array=( -what- this is ridiculous ) $ print - $array -what- this is ridiculous $ > I have bash and dash installed and neither have a problem with '-', > don't have ksh so don't know about it. Bash has problems with hyphens in the same places Zsh does (generally). The differences are a different set of built-in commands (no 'print', AFAICT), and that Zsh treats things as arrays more readily (maybe there's an option you can set, but I hate having to type ${array[@]}). Example of bash treating an array item as an argument: $ bash $ array=( -v What %s earth ) $ printf ${array[@]} ### (no output) $ echo $What earth -- Best, Ben ---1463810530-1263456510-1316466934=:10525--