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

Virden, Larry W. lvirden at cas.org
Thu Nov 3 16:48:32 UTC 2005


Ah - I see.  In the original ksh, the read is done within the same
process - no subprocess is created.  Thus the construct I used worked
just fine there.

Just another difference between pdksh and real ksh.

Thanks!

-----Original Message-----
From: redhat-list-bounces at redhat.com
[mailto:redhat-list-bounces at redhat.com] On Behalf Of Dave Ihnat
Sent: Thursday, November 03, 2005 11:47 AM
To: General Red Hat Linux discussion list
Subject: Re: Attempting to understand behavior of /bin/ksh's read
command

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 at dminet.com

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




More information about the redhat-list mailing list