From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14947 invoked from network); 13 Jan 2003 17:59:46 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 13 Jan 2003 17:59:46 -0000 Received: (qmail 29454 invoked by alias); 13 Jan 2003 17:59:33 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5688 Received: (qmail 29444 invoked from network); 13 Jan 2003 17:59:32 -0000 From: Carlos Carvalho Message-Id: <15906.65149.206767.381472@fisica.ufpr.br> Date: Mon, 13 Jan 2003 15:59:25 -0200 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: zsh-users@sunsite.dk Subject: Re: aliases not getting expanded inside functions? In-Reply-To: <1030111184020.ZM11764@candle.brasslantern.com> References: <15893.44217.393956.262362@fisica.ufpr.br> <20030103164552.A28966@globnix.org> <15893.50996.646711.184945@fisica.ufpr.br> <20030103184455.A5692@globnix.org> <15893.53780.524763.695176@fisica.ufpr.br> <20030103185407.GA11836@fysh.org> <15897.15986.562636.628562@fisica.ufpr.br> <1030106125404.ZM4660@candle.brasslantern.com> <15903.36155.716460.639226@fisica.ufpr.br> <1030111184020.ZM11764@candle.brasslantern.com> X-Mailer: VM 7.07 under Emacs 19.34.1 Bart Schaefer (schaefer@brasslantern.com) wrote on 11 January 2003 18:40: > : ${(P)1::=$2} > eval $1='$2' > typeset -g $1=$2 Nice! >Rather than: > > while read dataline > do > fields=( "${(@s:;:)dataline}" ) # Answers your other question Doesn't work for me: fields=( "${(@s:;:)dataline}" ) print LINE=$dataline for ((i=1; i <= 16; i++)) { print "fields[$i]=\"$fields[i]\"" } gives LINHA="BD CCE";"CCE";"210";"0";"1-254";33;7;1;;;;;;;"permit"; fields[1]=""BD CCE"" fields[2]=""CCE"" fields[3]=""210"" fields[4]=""0"" fields[5]=""1-254"" fields[6]="33" fields[7]="7" fields[8]="1" fields[9]=""permit"" <--- wrong fields[10]="" fields[11]="" fields[12]="" fields[13]="" fields[14]="" fields[15]="" <--- permit should be here fields[16]="" > rate=$fields[1] capital=$fields[2] etc. > # manipulate $rate $capital and so on ... > done > >You can simply do: > > while IFS=';' read rate capital etc. > do > # manipulate $rate $capital and so on ... > done Yes, I didn't do it because I had hope to one day do a block move via arrays. Also, reading to a parameter first makes it easier to do some pre-processing like quote removal, otherwise I have to do it field by field after reading. >If you're unwilling to use $fields[capital] everywhere -- that is, if >you insist on being able to write $capital in some cases -- then there >is no solution I can suggest. However, if it's OK to write e.g. > > fields[capital]=$((fields[capital]+fields[interest])) This makes the program more cumbersome to write and read because all variables become quite long-named...