Re: OT: quoting variable names in shell scripts
* 2011-07-07T07:13:24+02:00 * Javier Barroso wrote: On Thu, Jul 7, 2011 at 5:22 AM, Kamaraju S Kusumanchi raju.mailingli...@gmail.com wrote: Consider the following shell script #! /bin/sh You can use array variables if you want: names=(kama raju k a m a) for i in ${names[@]} Yes, but not with /bin/sh. OK, it's usually possible to just change the interpreter to /bin/bash, but with /bin/sh the $@ array can be used: $ set -- first item second item $ for i in $@; do echo $i; done first item second item -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/87liwaze2z@mithlond.arda
Re: OT: quoting variable names in shell scripts
On Thu, Jul 7, 2011 at 10:31 AM, Teemu Likonen tliko...@iki.fi wrote: * 2011-07-07T07:13:24+02:00 * Javier Barroso wrote: On Thu, Jul 7, 2011 at 5:22 AM, Kamaraju S Kusumanchi raju.mailingli...@gmail.com wrote: Consider the following shell script #! /bin/sh You can use array variables if you want: names=(kama raju k a m a) for i in ${names[@]} Yes, but not with /bin/sh. OK, it's usually possible to just change the interpreter to /bin/bash, but with /bin/sh the $@ array can be used: Ooops, true!! :) I have not an shell interpreter in my head :-P Thanks! -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/CAL5yMZTz5PV-xHP==ijqb_cmuxgvwoavhkewsvn17b_fnbe...@mail.gmail.com
Re: OT: quoting variable names in shell scripts
Kamaraju writes: I am wondering if there is a way to rewrite the names variable in stanza2 such that the output from stanza 1 and stanza 2 are the same. I can think of several, but I doubt any will do what you want. What is your actual problem? What are you trying to achieve? -- John Hasler -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/87hb6ydz41@thumper.dhh.gt.org
OT: quoting variable names in shell scripts
Consider the following shell script $cat manual_listing.sh #! /bin/sh # stanza 1 for i in kama raju k a m a r a j u do echo $i done # stanza 2 names='kama raju' for i in $names do echo $i done If I run this, I get $./manual_listing.sh kama raju k a m a r a j u kama raju I am wondering if there is a way to rewrite the names variable in stanza2 such that the output from stanza 1 and stanza 2 are the same. thanks in advance raju -- Kamaraju S Kusumanchi http://malayamaarutham.blogspot.com/ -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/iv38q5$a33$1...@dough.gmane.org
Re: OT: quoting variable names in shell scripts
On 07/06/11 at 11:22pm, Kamaraju S Kusumanchi wrote: Consider the following shell script $cat manual_listing.sh #! /bin/sh # stanza 1 for i in kama raju k a m a r a j u do echo $i done # stanza 2 names='kama raju' for i in $names do echo $i done If I run this, I get $./manual_listing.sh kama raju k a m a r a j u kama raju I am wondering if there is a way to rewrite the names variable in stanza2 such that the output from stanza 1 and stanza 2 are the same. =---= #!/bin/bash IFS=, name='kama,raju,k a m a,r a j u' for i in $name do echo $i done =---= $man bash Shell Variables ... IFSThe Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is ``spacetabnew‐ line''. -- Liam signature.asc Description: Digital signature
Re: OT: quoting variable names in shell scripts
On Thu, Jul 7, 2011 at 5:22 AM, Kamaraju S Kusumanchi raju.mailingli...@gmail.com wrote: Consider the following shell script $cat manual_listing.sh #! /bin/sh # stanza 1 for i in kama raju k a m a r a j u do echo $i done # stanza 2 names='kama raju' for i in $names do echo $i done If I run this, I get $./manual_listing.sh kama raju k a m a r a j u kama raju I am wondering if there is a way to rewrite the names variable in stanza2 such that the output from stanza 1 and stanza 2 are the same. You can use array variables if you want: names=(kama raju k a m a) for i in ${names[@]} do echo $i done Search [@ (probablily escaping both) inside man bash Regards, -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/CAL5yMZT8Bu14N1nt_tefMJNn5mHWK3nGtJ6fHnyMi+k=obo...@mail.gmail.com