Re: Attempting to understand behavior of /bin/ksh's read command

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

 



On Thu, Nov 03, 2005 at 11:07:59AM -0500, Virden, Larry W. wrote:
> $ echo aa bb cc dd | read a b c d
> 
> $ echo $a
> 
> /bin/ksh: a: parameter not set

Nothing's wrong; it's doing just what you told it to do.  You just told
it to do the wrong thing.

You told it to spawn a subshell--note the pipe--which certainly read
the output from the echo command, set its own variables a, b, c, and
d--and then destroyed them when it exited.  You can't set variables in
a parent from a child.

If you type:

	read a b c d
	This is a test
	echo $a $b $c $d

you'll see it's parsed them properly; everything is in the same shell.

So how do you redirect input ?  There are various ways.

	exec 0<filename

	echo aa bb cc dd | (
		read a b c d
		echo $a $b $c $d
	)

and so on.

Cheers,
--
	Dave Ihnat
	ignatz@xxxxxxxxxx

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux