From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6513 invoked from network); 19 Dec 2003 06:47:19 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 19 Dec 2003 06:47:19 -0000 Received: (qmail 3329 invoked by alias); 19 Dec 2003 06:47:06 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6925 Received: (qmail 3284 invoked from network); 19 Dec 2003 06:47:05 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 19 Dec 2003 06:47:05 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [68.1.17.113] by sunsite.dk (MessageWall 1.0.8) with SMTP; 19 Dec 2003 6:47:5 -0000 Received: from quark.localdomain ([68.12.75.33]) by lakemtao08.cox.net (InterMail vM.5.01.06.05 201-253-122-130-105-20030824) with ESMTP id <20031219064703.NPML2412.lakemtao08.cox.net@quark.localdomain> for ; Fri, 19 Dec 2003 01:47:03 -0500 Received: from quark.localdomain (localhost.localdomain [127.0.0.1]) by quark.localdomain (8.12.9/8.12.9) with ESMTP id hBJ6lCuO024215 for ; Fri, 19 Dec 2003 00:47:12 -0600 (CST) (envelope-from vince@quark.localdomain) Received: (from vince@localhost) by quark.localdomain (8.12.9/8.12.9/Submit) id hBJ6lCJw024214 for zsh-users@sunsite.dk; Fri, 19 Dec 2003 00:47:12 -0600 (CST) Date: Fri, 19 Dec 2003 00:47:10 -0600 From: Vincent Stemen To: zsh-users@sunsite.dk Subject: Re: Splitting string to array removes pipe symbol Message-ID: <20031219064710.GA24057@quark.localdomain> References: <20031216083449.GA9113@quark.localdomain> <11632.1071571889@csr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <11632.1071571889@csr.com> User-Agent: Mutt/1.4.1i On Tue, Dec 16, 2003 at 10:51:29AM +0000, Peter Stephenson wrote: > Vincent Stemen wrote: > > However, when the globsubst option is set, it removes the pipe '|' > > symbol when it does the split. Here is the trace output. > > > > +./t:62> cmd=uncompress foobar | cpio -i --quiet --unconditional > > +./t:63> cmd=( uncompress foobar cpio -i --quiet --unconditional ) > > You have null_glob (or maybe csh_null_glob) set. `|' is split to a > single bar. Evaluation of the words takes place as if all the elements > of the array are arguments, which is different from evaluating as a > command. (This is inevitable --- the only way of doing it differently > would be to parse the line again completely from scratch after the > glob_subst.) In this case, the `|' is treated the same as (|), > i.e. either nothing or nothing, and removed since nothing matches it. > (You'd normally need the parentheses to stop it being evaluated as a > pipe, but it can't be in an argument list.) > > You can fix this particular problem by quoting, > cmd=("${(@)=cmd}") > but only because that cancels the effect of glob_subst, so that `|' is > just an ordinary character. This may not be what you want. It's > likely to be very difficult to force the shell both to split a line into > words *and* to parse it again as a full command line without joining it > up again. > > Most people would probably come up with something using `eval'. What you > should do depends why you need to split it at all. I appreciate the quick reply. You pinpointed exactly what the problem was. I did indeed have null_glob set. I am learning to pay close attention to the combination of options I have set when I get unexpected behavior in Z shell scripts :-). Putting quotes around the variable to be split did preserve the '|' character. However, I saw no difference in the result in this case whether I used the (@) flag or did it with cmd=("${=cmd}"). The reason I was experimenting with splitting the line before execution is because when I didn't, and ran "eval $cmd", I was getting a null argument to eval. Your reply pointed me in the right direction to solve that mystery also :-). I investigated further and found that was also because of a null pattern expansion of the entire string. My final solution was to not split the string, use eval, and disable glob_subst for the $cmd variable using "~~" (ie. eval ${~~cmd}). Thank you very much for devoting your time to help. - Vincent -- Vincent Stemen Avoid the VeriSign/Network Solutions domain registration trap! http://www.InetAddresses.net