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
...
       IFS    The  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  ``<space><tab><new‐
              line>''.

-- 
Liam

Attachment: signature.asc
Description: Digital signature

Reply via email to