Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: kinda perl split ...



On Tue, Mar 21, 2006 at 03:22:29PM +0100, Marc Chantreux wrote:
> Dominic Mitchell wrote:
> 
> >  echo foo bar | while read a b junk
> >  do
> >    echo "a=$a b=$b"
> >  done
> 
> so if the separator is ':', you should redefine IFS
> 
> oldIFS=$IFS
> IFS=':'
> echo foo bar | while read a b junk
> do
>      echo "a=$a b=$b"
> done
> IFS=$oldIFS
> oldIFS=
> 
> or with a subshell:
> 
> ( IFS=':'
> echo foo bar | while read a b junk
> do
>      echo "a=$a b=$b"
> done )

Or even simpler, just redefine the variable for that read command:

    echo foo:bar | while IFS=: read a b junk
    do
        echo "a=$a b=$b"
    done

-Dom



Messages sorted by: Reverse Date, Date, Thread, Author