ksh read buildin function

ksh read buildin function

Post by kamin » Sun, 16 Oct 2005 18:25:35



Dear all,

It is found that the read Public domain version of ksh can't read variable
from pipe ...

i.e.

# A="Hello"
# echo $A | read B
# echo $B

However, I found that the above syntax was correctly in commercial version
of ksh like AIX and Solaris..

Do any one have idea on how to solve this problem?

Thanks!

Henry

 
 
 

ksh read buildin function

Post by Janis Papanagno » Sun, 16 Oct 2005 21:41:46



> Dear all,

> It is found that the read Public domain version of ksh can't read variable
> from pipe ...

> i.e.
> # echo $KSH_VERSION

> # A="Hello"
> # echo $A | read B
> # echo $B

Isn't that answered in the FAQ? In pdksh (and some other shells) the read
is executed in a subshell thus the value of B unavailable to echo. For ksh...

        What is $bar after,     echo foo | read bar?

        The is foo.  ksh runs the last component of a pipeline
        in the current process.  Some shells run it as a subshell
        as if you had invoked it as  echo foo | (read bar).

Quote:> However, I found that the above syntax was correctly in commercial version
> of ksh like AIX and Solaris..

> Do any one have idea on how to solve this problem?

I'd get the real ksh from www.kornshell.com; it's free.

A workaround is to put read B and echo $B into the same subshell by using a
compound command block (or a subshell bracket)...

echo $A | { read B; echo $B; }

Quote:> Thanks!

> Henry

Janis

 
 
 

ksh read buildin function

Post by Bill Marcu » Sun, 16 Oct 2005 21:48:42


On Sat, 15 Oct 2005 17:25:35 +0800, kaming

> Dear all,

> It is found that the read Public domain version of ksh can't read variable
> from pipe ...

It's not that it can't read, it's that pdksh behaves like most other
shells: each process in a pipe is a subshell with its own variables,
which are gone when the process ends.

> i.e.
> # echo $KSH_VERSION

> # A="Hello"
> # echo $A | read B
> # echo $B

> However, I found that the above syntax was correctly in commercial version
> of ksh like AIX and Solaris..

> Do any one have idea on how to solve this problem?

echo $A | (read B; echo $B)
Download ksh from kornshell.com or use zsh.

--
The wind doth taste so bitter sweet,
        Like Jaspar wine and sugar,
It must have blown through someone's feet,
        Like those of Caspar Weinberger.                -- P. Opus

 
 
 

ksh read buildin function

Post by bsh » Mon, 24 Oct 2005 08:44:13



> # echo $A | read B
> ...

Just to expound upon the previous threads: this behavior
peculiar to ksh(1) and ksh93(1) is a consequence of executing
the last component of a pipe in a "new process environment",
and not a new (forked) process, as a speed optimization. Relying
on this behavior is officially deprecated, as Korn & Bolsky
state in both editions of their book, and "may disappear at
any time."

=Brian

 
 
 

ksh read buildin function

Post by Dan Merce » Tue, 25 Oct 2005 03:46:18


: > # echo $A | read B
: > ...
:
: Just to expound upon the previous threads: this behavior
: peculiar to ksh(1) and ksh93(1) is a consequence of executing
: the last component of a pipe in a "new process environment",
: and not a new (forked) process, as a speed optimization. Relying
: on this behavior is officially deprecated, as Korn & Bolsky
: state in both editions of their book, and "may disappear at
: any time."
:
: =Brian
:

That's nor going to happen,  as that feature is the main reason to
use Korn shell over other shells,  and has been incorporated into
other vendor's posix shells,  like HP-UX.  Its removal would likely cause
the failure of 80% of all ksh scripts.

Please don't spread FUD - leave that to M$.

Dan Mercer

 
 
 

ksh read buildin function

Post by Sven Maschec » Wed, 26 Oct 2005 01:29:49



> [...] that feature is the main reason to use Korn shell over other shells,
> and has been incorporated into other vendor's posix shells, like HP-UX.

nitpick: commercial POSIX-Shells are derived from the korn shell
 
 
 

ksh read buildin function

Post by bsh » Wed, 26 Oct 2005 10:17:35





> > > "may disappear at any time."
> That's nor going to happen,  as that feature is the main reason to
> use Korn shell over other shells,  and has been incorporated into
> other vendor's posix shells,  like HP-UX.  Its removal would likely cause
> the failure of 80% of all ksh scripts.

Mr. M, it's _me_, Brian! I _know_ that you know what
I should be knowing, especially about this matter!

Well of course you are accurate -- if not "correct".... I am
well aware that 5% of all posts in C.U.S. devolves to this very
issue ;) I couldn't locate this in a quick scan in the FAQ
though -- it should be one!

Please please don't hate me; I'm just reporting the facts.

Quote:> Please don't spread FUD - leave that to M$.

BTW, What's "FUD"? "Fractious Ulcerating Discourse"?

=Brian ("Don't tell A.C. that I post via Google Groups.")

 
 
 

ksh read buildin function

Post by Dan Merce » Wed, 26 Oct 2005 12:30:40




: > > > "may disappear at any time."
:
: > That's nor going to happen,  as that feature is the main reason to
: > use Korn shell over other shells,  and has been incorporated into
: > other vendor's posix shells,  like HP-UX.  Its removal would likely cause
: > the failure of 80% of all ksh scripts.
:
: Mr. M, it's _me_, Brian! I _know_ that you know what
: I should be knowing, especially about this matter!
:
: Well of course you are accurate -- if not "correct".... I am
: well aware that 5% of all posts in C.U.S. devolves to this very
: issue ;) I couldn't locate this in a quick scan in the FAQ
: though -- it should be one!
:
: Please please don't hate me; I'm just reporting the facts.
:
: > Please don't spread FUD - leave that to M$.
:
: BTW, What's "FUD"? "Fractious Ulcerating Discourse"?
Fear - Uncertainty - Doubt - a business tactic pioneered by
IBM that came to light in the CDC lawsuit,  a practice
wholeheartedly adopted by M$.

Dan Mercer

:
: =Brian ("Don't tell A.C. that I post via Google Groups.")
:

 
 
 

ksh read buildin function

Post by j.. » Wed, 26 Oct 2005 23:16:58






> > > > "may disappear at any time."

> > That's nor going to happen, as that feature is the main reason to
> > use Korn shell over other shells, and has been incorporated into
> > other vendor's posix shells, like HP-UX.  Its removal would likely
> > cause the failure of 80% of all ksh scripts.

> Mr. M, it's _me_, Brian! I _know_ that you know what
> I should be knowing, especially about this matter!

> Well of course you are accurate -- if not "correct".... I am
> well aware that 5% of all posts in C.U.S. devolves to this very
> issue ;) I couldn't locate this in a quick scan in the FAQ
> though -- it should be one!

It sort of is, but the question is about losing values inside a loop:

http://home.comcast.net/~j.p.h/cus-faq-2.html#33

It could probably do with some enhancement (in fact, it may be wrong
in a couple places), and maybe the question should be made broader to
include this kind of thing.

Joe
--
Gort, klatu barada nikto

 
 
 

1. ksh head ache - here doc within a ksh function


: > Xref: eecal.scotnet.co.uk comp.unix.shell:1413
: > Path: eecal.scotnet.co.uk!florence.scotnet.co.uk!uknet!demon!doc.news.pipex.net!pipex!howland.reston.ans.net!news-e1a.megaweb.com!newstf01.news.aol.com!newsbf02.news.aol.com!not-for-mail

: > Newsgroups: comp.unix.shell
: > Date: 17 May 1995 22:28:08 -0400
: > Organization: America Online, Inc. (1-800-827-6364)
: > Lines: 20


: > NNTP-Posting-Host: newsbf02.mail.aol.com
: >
: > Dear knowledgable source,
: > I am attempting to embed a here-doc within a ksh function.
: > The file looks like the following:
: > #!/bin/ksh
: > function a
: > {
: >    cat <<EOI
: >    This is a string for cat to display.
: >    EOI
: > }
: You'll kick yourself!
: The second EOI has to by flush with the left margin to match the first ie:
: function a
: {
:     cat <<EOI
:     This is a string for cat to display.
: EOI
: }

But this puts unwanted white space into the string.
Try:
{
     cat <-EOI
<TAB>This is a string for cat to display.
<TAB>EOI

where,  of course, <TAB> represents a physical tab.

--
Dan Mercer                                            ClearSystems, Inc

======================================================================
All opinions expressed are my own and do not reflect the opinions of
my employer or my employer's clients,  in particular 3M Company.
All advice or software offered or presented is provided As Is with no
warranty either expressed or implied.  Follow at your own risk.
Objects in the mirror are closer than they appear.

2. boot message: maximum mount count, check forced ??

3. S3 Xserver hangs in 3.1.2 and 3.1.2D

4. ksh -x does not work on function inside a function

5. Black Box splitter to Cisco

6. ksh, read reads files funny

7. Sz and Multi VCs

8. function, function...who's got the function?

9. recursive functions in ksh

10. How to find the contents of a KSH function.

11. ksh functions/main

12. Shell function and typeset in ksh