dtksh (ksh 93) timed read

dtksh (ksh 93) timed read

Post by Brendan Greg » Fri, 18 Jun 2004 19:30:03



G'Day,

Does anyone know an elegant way to do a timed read in dtksh?

I need dtksh to try a "read line" statement for half a second, then give
up if nothing has been read. I solved it by using a watchdog process to
sleep then send a signal - but I don't want to be forced to use a
watchdog...

I can't use another shell as I'm using dtksh's X11 features... :)

thanks,

Brendan

[Sydney, Australia]

 
 
 

dtksh (ksh 93) timed read

Post by Stephane CHAZELA » Fri, 18 Jun 2004 20:53:22


2004-06-17, 20:30(+10), Brendan Gregg:
Quote:> Does anyone know an elegant way to do a timed read in dtksh?

[...]

ksh93 has a (problematic) feature for that, the TMOUT variable:

TMOUT=3 dtksh -c 'read var'

--
Stephane

 
 
 

dtksh (ksh 93) timed read

Post by Brendan Greg » Fri, 18 Jun 2004 21:49:03


G'Day,


Quote:> 2004-06-17, 20:30(+10), Brendan Gregg:
> > Does anyone know an elegant way to do a timed read in dtksh?
> [...]

> ksh93 has a (problematic) feature for that, the TMOUT variable:

> TMOUT=3 dtksh -c 'read var'

This creates a child dtksh process to read the var then exits, losing the
setting - my script needs to keep going regardless, with or without a
populated variable. I guess I could keep it using,

  line=`TMOUT=3 dtksh -c 'read line; echo $line'`

which is back to being not very elegant. (my script does this once every
second, I'd rather not run a dtksh every second if I can avoid it).

This might be what you mean by problematic - TMOUT always exits, it would
be nice if TMOUT sent a signal instead that could be trapped.

thanks for your reply!

Brendan

[Sydney, Australia]

 
 
 

dtksh (ksh 93) timed read

Post by Heiner Steve » Fri, 18 Jun 2004 22:48:47



> G'Day,

> Does anyone know an elegant way to do a timed read in dtksh?

> I need dtksh to try a "read line" statement for half a second, then give
> up if nothing has been read. I solved it by using a watchdog process to
> sleep then send a signal - but I don't want to be forced to use a
> watchdog...

"dtksh" is based on ksh93. I don't know what version your dtksh is,
but newer versions (like ksh93 Version M 1993-12-28 m) have
a "read -t timeout" option:

     read -t 3 line

Heiner
--
  ___ _

\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/

 
 
 

dtksh (ksh 93) timed read

Post by Brendan Greg » Sat, 19 Jun 2004 08:37:20


G'Day,



> > G'Day,

> > Does anyone know an elegant way to do a timed read in dtksh?

> > I need dtksh to try a "read line" statement for half a second, then give
> > up if nothing has been read. I solved it by using a watchdog process to
> > sleep then send a signal - but I don't want to be forced to use a
> > watchdog...

> "dtksh" is based on ksh93. I don't know what version your dtksh is,
> but newer versions (like ksh93 Version M 1993-12-28 m) have
> a "read -t timeout" option:

>      read -t 3 line

Ahh! That's exactly what I was looking for - it's just not in my man
pages. I should have tried it anyway :)

... My dtksh man page just has the desktop features, so I was reading the
ksh man page for regular syntax. Problem was - the regular ksh man page
was for '88 ksh, not '93 (I'm on Solaris 9).

ksh93 and bash don't seem to do fractions of seconds. I think I'd better
go hunt down the real man page.

Thanks Heiner,

Brendan

[Sydney, Australia]

 
 
 

dtksh (ksh 93) timed read

Post by Markus Gyg » Sat, 19 Jun 2004 14:02:14




> >      read -t 3 line
> My dtksh man page just has the desktop features, so I was reading the
> ksh man page for regular syntax. Problem was - the regular ksh man page
> was for '88 ksh, not '93 (I'm on Solaris 9).

Use "man -M/usr/dt/man ksh93" (the references in the dtksh(1) man page
should be fixed in Solaris Express next month). The next release of
ksh93 will most likely also support floating point numbers for read -t,
similar to like sleep does in more recent versions.

Markus

 
 
 

dtksh (ksh 93) timed read

Post by Brendan Greg » Sat, 19 Jun 2004 19:25:05


G'Day Markus,




> > >      read -t 3 line
> > My dtksh man page just has the desktop features, so I was reading the
> > ksh man page for regular syntax. Problem was - the regular ksh man page
> > was for '88 ksh, not '93 (I'm on Solaris 9).

> Use "man -M/usr/dt/man ksh93" (the references in the dtksh(1) man page
> should be fixed in Solaris Express next month). The next release of

I'm glad someone at Sun is thinking about dtksh! :)

A search for "dtksh" on the web shows little interest in it, which is a
pity as I think it has a lot of potential..

I'd love someone from the Linux world to start thinking about it too.
I've yet to see a Linux version.

Quote:> ksh93 will most likely also support floating point numbers for read -t,
> similar to like sleep does in more recent versions.

Fairdinkum! This is going to be very useful if they do put it in. I have
a few scripts (xvmstat, xplot) that would be much better with fractional
timed reads. They are linked on http://www.sun.com/bigadmin/scripts .

thanks,

Brendan

[Sydney, Australia]

 
 
 

1. ksh 93?

I see references to ksh93 in these postings.  How do I know if that is the "version" of ksh i'm using?

Also, I've been reading a book on ksh (Learning the Korn Shell, Rosenblatt, O'reilly and Assoc), and
he recommends syntax that is different that scripts that I am running, and from the scripts I've seen
posted here.  Most noticably, he calls archaic the `Command Substition` syntax , saying that it should
be $(Command substitution) , and secondly the way Functions are defined .  He prefers to use

function FUNCTNAME {
        commands

But I see
FUNCNAME () {
        commands
        used here more frequently.  Can anyone tell me if these are the way that most people write
these scripts??  Any comments would be appreciated?

Tony Block

(Delete the xxx in the header to respond)

2. Tough Partition Problem

3. ksh'93 user defined builtin exit-code anomaly

4. What should I do after removing a cd-writer?

5. ksh'93 on Linux without conflicts with existing shells

6. Xconfig for an HP 486 Vectra, anyone?

7. ksh'93 getopts --longoptions

8. need to network RH 5.1 with Windows 98

9. ksh(93|Solaris) history up/down/search, TAB filename/variable completion...

10. KSH-93

11. Problem with shell history (ksh'93 on Linux)

12. ksh-93 getopts and + options

13. ksh (88/93), setting of PATH in ~/.profile