Re: OT: quoting variable names in shell scripts
On Thu, Jul 7, 2011 at 5:22 AM, Kamaraju S Kusumanchi
<raju.mailinglists@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,
Reply to: