[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Stupid shell script question about "read"



On Thu, Mar 02, 2006 at 10:23:20AM -0500, Kevin B. McCarty wrote:
> Hi list,
> 
> Could someone tell me why the following works in zsh but not in
> bash/posh/dash?
> 
> benjo[3]:~% echo foo bar baz | read a b c
> benjo[4]:~% echo $a $b $c
> foo bar baz
> 
> If I try the same with bash (or other sh-compatible shells), the
> variables $a $b and $c are unset.  From the bash man page:
> 
> 
> Posh and dash behave like bash in this respect, so I guess that this is
> not a bug, and that what zsh does is actually an extension.  So, what is
> the correct POSIX-compatible way to get "read" to work as I want?
> 
I think the POSIX way would be
echo foo bar baz | { read a b c; echo $a $b $c; }


-- 
Some people cause happiness wherever they go; others, whenever they go.



Reply to: