From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19511 invoked from network); 19 Jan 2003 06:33:25 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 19 Jan 2003 06:33:25 -0000 Received: (qmail 18296 invoked by alias); 19 Jan 2003 06:33:06 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5752 Received: (qmail 18282 invoked from network); 19 Jan 2003 06:33:06 -0000 X-MessageWall-Score: 0 (sunsite.dk) From: "Bart Schaefer" Message-Id: <1030119063306.ZM31331@candle.brasslantern.com> Date: Sun, 19 Jan 2003 06:33:06 +0000 In-Reply-To: <20030118233214.43327.qmail@web12305.mail.yahoo.com> Comments: In reply to Le Wang "parameter expansion question" (Jan 18, 6:32pm) References: <20030118233214.43327.qmail@web12305.mail.yahoo.com> X-Mailer: Z-Mail (5.0.0 30July97) To: Zsh users list Subject: Re: parameter expansion question MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jan 18, 6:32pm, Le Wang wrote: } } I can force a variable to be expanded by using } ${~var}. The only difference between ${var} and ${~var} is that in the latter case the resulting value is subject to filename generation. It does not "force" anything -- if filename generation would not normally occur in the context, using ${~var} will not cause it to happen. Perhaps you understood that already, but it's a commom mistake. } Is there any way I can force a string to be } expanded without assigning it to a variable first? What does "be expanded" mean to you? I thought at first you were talking about filename generation, but then you said: } I'm after the same information for filename generation. This question is almost meaningless. In most contexts, strings are subject to filename generation. In contexts where filenames are not generated, assigning to a variable won't help. If "be expanded" means you want to use other parameter operations such as ${var%pattern} on the string: Yes, you can do that, like this: zsh% print ${${:-some string here}% here} some string } Right now, if I want to see if the glob pattern } '(#i)${i%.rar}*.par' would match anything, I would do: } } parFile=`print (#i)${i%.rar}*.par` And then what? "Want to see if [it] would match" could mean several things. It could mean you want want to test whether there are any matches, e.g. [[ -n $parFile ]], or that you just want to print out what the matches are so you can look at them, or ... I suspect you mean that you want to find out whether, for each file matching "*.rar", there exists a file with the same root name and the extension ".par" -- but I've no idea what you want to do with that information once you have it. Perhaps this will help: print (#i)*.rar(e:'REPLY=${REPLY%.rar}.par && [[ -f $REPLY ]] || reply=()':) } if I use: } } parFile=(#i)${i%.rar}*.par } } Zsh thinks I want an array. There are several things going on here. Firstly, unless you use `setopt glob_assign', zsh doesn't do filename generation during assignment to scalar variables, so you wouldn't get what you expect there anyway. Secondly, it is true that there's an ambiguity with using parens for glob modifiers and using them to wrap array assignments. This should probably be considered a bug (agree, PWS?) which can be worked around by using the "${:-string}" trick I showed above: parFile=${:-(#i)${i%.rar}*.par} Finally, even if you use the workaround with glob_assign set, whether the variable is set as a string or as an array depends on whether the glob matches one or more than one file. So you're probably better off using an array to begin with, that is: parFiles=( (#i)${i%.rar}*.par ) which requires neither glob_assign (because filename generation IS always done during array assignments) nor any strange workarounds. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net