Re: [ast-users] trap issue

2017-04-27 Thread Janis Papanagnou
Thanks for your reply!


WRT "ERR"; you're right, and I shouldn't have mentioned POSIX here

since in most cases I anyway care only about the prominent shells,

i.e. [AST] ksh, bash, and zsh, where ERR is supported. Sorry for my

misleading formulation!


I am aware how to interrogate exit status of individual commands,

that was not the point here. I want to catch and remap _all_ errors

using a handler. So I was astonished that ksh - as opposed to bash

and zsh! - doesn't seem to behave correctly, or at least not as I'd

have expected.


Elsewhere I've been proposed installing an EXIT handler and emulate

the ERR handling on my own, like this:


sig_was_caught=

sig_handler()
{
  sig_was_caught=y
  exit 9
}

exit_handler()
{
  saved_status=$?
  if [ $sig_was_caught ] ; then
printf "Execution aborted!\n"
exit $saved_status
  elif [ $saved_status -ne 0 ] ; then
printf "An error occurred!\n"
exit 8;
  fi
}


that's fine but a bit bulky, and I'd prefer using a simple ERR trap

which *does* work correctly (or as expected) in bash and zsh.


But maybe I'm missing something...?


Janis


Von: Bruce Lilly <bruce.li...@gmail.com>
Gesendet: Donnerstag, 27. April 2017 22:51
An: Janis Papanagnou
Cc: ast-us...@research.att.com
Betreff: Re: [ast-users] trap issue

trap ... ERR isn't recognized by NetBSD (supposedly POSIX-compliant) /bin/sh,
so any script using that won't run under that shell.

Specific commands' return status can be used to detect errors, e.g.:

some_command
if test 0 -ne $? ; then printf "some_command failed\n" ; exit 8 ; fi

or more simply:

some_command || ( printf "some_command failed\n" ; exit 8; )

It's possible to encapsulate the equivalent of your ERR trap as a function
(but note that the NetBSD /bin/sh only groks Bourne shell function
definitions), e.g.:

error_handler() { printf "An error occurred!\n"; exit 8; }
...
some_command || error_handler

Without the ERR trap, signal traps plus the above (ERR isn't a signal)
should work with most signals and shells.  But unless you like core
dumps, don't trap CHLD if running with pdksh or mksh...

If you forego compatibility and use ERR, you can avoid triggering it
for some specific commands by using a command list guaranteed to
return 0 status, e.g.:

{ sleep 10 || true;} # N.B. opening brace must be the first character on the 
line

___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


[ast-users] Location of ksh man pages?

2016-02-11 Thread Janis Papanagnou
It seems the man pages for ksh88/ksh93 vanished from kornshell.com/doc

for some time now. Is there a new location where the official documents

can be got from?


Janis

___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] ksh - printf '%R'

2015-07-02 Thread Janis Papanagnou
 On Saturday, June 13, 2015 06:59:21 AM Janis Papanagnou wrote:
  It seems that ksh's printf %R is producing wrong results for negated 
  glob-patterns:
  
  $ printf %R\n !(*bak)
  ^(.*bak)!$
  
  $ echo $'abc\nabcbak\ndef' | grep -E '^(.*bak)!$'
  ...empty result...
  
[...]
 
 Is a regex equivalent to !() possible at all using any typical set of
 features? Since negative lookbehind generally doesn't support quantifiers
 I've never found a working solution even using fancy regex dialects. It
 likely requires conditional regex and some tricky use of (?R), if it's
 possible at all.

Yes, it's possible, just not as trivial as with the simple other forms (*, +, 
?),
where you can apply a  (mechanical) one-to-one mapping and only have
to consider anchors.

(Someone recently explained it based on an example, but currently I cannot
find that Usenet(?) or StackExchange(?) posting.) You actually need to break
the simple form !(...) into a sequence of variants of sub-regexps with negated
character classes. Specificall there's no look-behind (or similar) necessary to
achieve that. The transformation is not trivial and error-prone to do by hand,
so an automatism (one that works) like the above mentioned %R would have
been really nice, specifically for the negation.

 
 -- 
 Dan Douglas
 
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


[ast-users] ksh - printf '%R'

2015-06-12 Thread Janis Papanagnou
It seems that ksh's printf %R is producing wrong results for negated 
glob-patterns:

$ printf %R\n !(*bak)
^(.*bak)!$

$ echo $'abc\nabcbak\ndef' | grep -E '^(.*bak)!$'
...empty result...

I'm aware that a conversion of a negation glob to regexp is not trivial to 
implement,
but I'd like to know: Is this a known issue, and are there plans to fix that?

Thanks!

  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Accuracy of FP arithmetics

2015-05-15 Thread Janis Papanagnou
Ben, what ksh version are you using (and on what system)?

$ print $(( log(1000)/log(10)+1 ))
4

$ ksh --version
  version sh (ATT Research) 93u+ 2012-08-01

This is on a 64 bit Linux 3.2.0


From: balt...@air.org
To: janis_papanag...@hotmail.com; ast-us...@research.att.com
Subject: RE: [ast-users] Accuracy of FP arithmetics
Date: Fri, 15 May 2015 12:13:08 +









$ print $(( log(1000)/log(10)+1 ))
3.99961
 
$ print  $(( int(log(1000)/log(10))+1 ))
3
 
Ben
 


From: ast-users-boun...@lists.research.att.com 
[mailto:ast-users-boun...@lists.research.att.com]
On Behalf Of Janis Papanagnou

Sent: Friday, May 15, 2015 6:23 AM

To: ast-us...@research.att.com

Subject: [ast-users] Accuracy of FP arithmetics


 

This is a question of *how* does it ksh *right* where other tools (awk) fail.



The task was to get the number of digits in a decimal number. (N.B.: the log()

division was used instead of log10() because of the latter's unavailability in

awk.)



$ awk 'BEGIN {print (log(999)/log(10))+1}'

3.99957

$ awk 'BEGIN {print (log(1000)/log(10))+1}'

4



Adding an int() call to above functions:



$ awk 'BEGIN {print int(log(999)/log(10))+1}'

3

$ awk 'BEGIN {print int(log(1000)/log(10))+1}'

3



The last result is wrong (due to internal rounding/accuracy problems in FP

arithmetics [see Goldberg's paper on FP arithmetics]).



Contrary to awk, ksh correctly does (without and with the int() call):



$ echo $(( log(1000)/log(10)+1 ))

4



$ echo $(( int(log(1000)/log(10))+1 ))

4



I'm assuming that both tools, awk and ksh, use C library functions for FP

arithmetic. - What does ksh internally do to create a correct result?

  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Problem with ksh read -n

2015-03-17 Thread Janis Papanagnou



Thanks for you explanations! - My notes below...

 Date: Tue, 17 Mar 2015 17:19:24 -0500
 From: terrence.j.doyle+...@gmail.com
 
   There are two points, here.
 
   First, you're using an old version of ksh.

Yes, I'm aware and noted that myself. I'd be happy if newer ksh's
behaviour would not only be different than older ksh's, but also...
(see below)

 
   Second, ksh has a different spin from bash on reading fixed-length
 data. Read sees variables in two flavors, text and binary.

I'm in this case primarily interested in text.

 When read
 puts characters into a textual variable newlines are always changed to a
 null character which serves as a string terminator. Also, when ksh reads
 fixed-length data, characters continue to fill the buffer after a
 newline is read. Thus, any characters read into your line variable
 after a newline will effectively disappear.

Diasappearing characters when processing ordinary text is what
annoys and surprises me; also conceptually.

The man page says:
The
-n
option causes at most
n 
bytes to read rather a full line
but will return when reading from a slow device
as soon as any
characters have been read.

No mention of discarding any characters. (And why would that
make more sense than reading up to the desired amount, and
keep the rest for another read.)

(And I didn't specify -N, to read exactly an amount of characters,
I called it with -n, to read at most the given amount of characters.)

 
   When I run your test with ksh-20140929, I get these results:
 
 'ABCDEFGHIJ123456'
 '7890'
 '234567890'

(Frankly, this shocks me even more than the output I got from that
older ksh version I used.)

 
 The first 16 characters are put into line as expected and printf %s
 displays them. In the next loop iteration read puts another 16
 characters into line but changes the newline to a null character. Printf
 %s sees the null character as end-of-string and prints only 7890.

That's fine and as expected.

 Characters 6 through 16 (abcdefghij1) in line can't be seen using printf
 %s.

Here I see the problem. According to read's option -n, it should not
read more than the 6 characters (i.e. insert a NUL, and then another
string of chracters). Rather it should read just 6 characters and
aborting the read while skipping the NL and terminating the string
internally with NUL. So that the rest is available for the next read.

 In the final iteration the remaining characters are put in line and
 printf %s displays them.
 
   If you don't want ksh to change newlines to null characters in
 fixed-length data, you need to use binary variables.

No, what I would want is that there's not more characters read than
asked for.

All the features related to binary processing is not what I wanted;
I just want to do (non-binary, printable characters) text processing.

 Binary variables
 are declared with typeset -b. To print binary variables you should use
 printf %B. As with textual variables read will continue to fill the
 buffer after a newline is read. I modified your example for binary
 variables as follows:
 
 typeset -b line
 while IFS= read -n16 -r line
 do
 printf -- '%B'\n line
 done EOT
 ABCDEFGHIJ1234567890
 abcdefghij1234567890
 EOT
 
 This produced the following output:
 
 'ABCDEFGHIJ123456'
 '7890
 abcdefghij1'
 '234567890
 '

(A change to binary processing is not what I wanted to achieve, so the
results of your changes naturally don't reflect the expected outcome.)

 
 It might be more appropriate to change line to buffer to go along
 with ksh's behavior.
 
   It's still different from bash, but I'm content letting ksh be ksh and
 bash be bash.

To be clear; it's *not* about ksh imitating bash. It's about a behaviour
of ksh's read that's (IMO) extremely surprising (and [IMO] not helpful).

 I don't know if the new bash compatability-mode makes
 reading fixed-length data closer to bash's style.

I'm not a bash user (usually), I very much prefer ksh. But methinks the
visible behaviour of read -n is not intuitive, specifically when it comes
to silently discarding characters.

The explanations here left me with a feeling that read -n behaves the
way it is because it's technically implemented in the way it is. Not really
satisfying.

But thanks again. - More insights about why the given read -n behaviour
is more sensible than bash's (in this specific read -n case) is welcome.

 
   Terrence Doyle
 
 On 3/15/15 9:10 AM, Janis Papanagnou wrote:
  I observe a problem (see testcase below) with ksh's read -n.
  (Version 93t 2008-11-04 on Cygwin).
  Bash's behaviour would be what I expect.
  Ksh doesn't read the second line and doesn't terminate output.
  (Maybe an old bug fixed in newer versions? Or am I missing something?)
  
  --snip--
  
  $ cat readtest
  while IFS= read -n16 -r line
  do
printf '%s'\n $line
  done EOT
  ABCDEFGHIJ1234567890
  abcdefghij1234567890
  EOT
  
  $ bash readtest | head
  'ABCDEFGHIJ123456

[ast-users] Problem with ksh read -n

2015-03-15 Thread Janis Papanagnou
I observe a problem (see testcase below) with ksh's read -n.
(Version 93t 2008-11-04 on Cygwin).
Bash's behaviour would be what I expect.
Ksh doesn't read the second line and doesn't terminate output.
(Maybe an old bug fixed in newer versions? Or am I missing something?)

--snip--

$ cat readtest
while IFS= read -n16 -r line
do
  printf '%s'\n $line
done EOT
ABCDEFGHIJ1234567890
abcdefghij1234567890
EOT

$ bash readtest | head
'ABCDEFGHIJ123456'
'7890'
'abcdefghij123456'
'7890'

$ ksh readtest | head
'ABCDEFGHIJ123456'
'7890'
''
''
''
''
''
''
''
''

$ ksh --version
  version sh (ATT Research) 93t 2008-11-04

--snip--

  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] how to get functionality of bash compatible PS1 without rest of bash compatibility?

2015-03-12 Thread Janis Papanagnou
Well, I'll abstain from diving into your code; you're right, it's quite ugly.  
:-)
For the date calculations part of your question the easiest may be to use some 
builtins.

The following create the current date and the date t0 from the current day, 
both in seconds...
t_now_s=$( printf %(%s)T\n )
t0_s=$( printf %(%s)T\n $(date +%Y) )
seconds_diff=$(( t_now_s - t0_s ))

(Maybe it's even easier than that to achieve, but I think this is already more 
legible then what you have.)


Subject: Re: [ast-users] how to get functionality of bash compatible PS1 
without rest of bash compatibility?
From: rlham...@gmail.com
Date: Thu, 12 Mar 2015 17:26:58 -0400
CC: ast-users@lists.research.att.com
To: janis_papanag...@hotmail.com

My code does NOT attempt to provide bash PS1 compatibility, it just plugs in a 
time and truncated (leading levels) directory; the time is based on a computed 
offset since midnight to add to SECONDS, so it doesn’t need to run builtins 
when PS1 is evaluated.  It works, and the performance isn’t horrible, but it’s 
ugly beyond all recognition.
Some of it’s mine, some of it (the directory part for sure; can’t remember 
whether the start of the time code was mine or a scrounge) is scrounged.  
Basically I make a PS0 that will later (within function _cd) become part of PS1.
Before, I actually reset SECONDS to be seconds since midnight, but I recently 
changed it to be an offset added to SECONDS, so as to leave SECONDS unaltered 
and be able to stick it in PS4 along with a set -x at the top of my .profile, 
trying to track down an annoying variation from  1 sec to  10 sec in how long 
it takes to start a new login shell.
cd is aliased to function _cd, which runs real ‘cd’ and diddles the path part 
of PS1.
Here’s the PS0 (time) part:   eval export _offset=$(( $(/bin/date 
'+3600*%H+60*%M+%S') - ${SECONDS} ))   _pad[1]=0;_pad[2]=''   
_hh=((SECONDS+${_offset})/3600)%24   _mm=((SECONDS+${_offset})/60)%60   
_ss=((SECONDS+${_offset}))%60   
_time='${_x[(_m=_mm)==(_h=_hh)==(_s=_ss)]}${_pad[${#_h}]}$_h:${_pad[${#_m}]}$_m:${_pad[${#_s}]}$_s'
   PS0=$_time[!]${_hostname%%.*}:
Like I said, I don’t even really understand the line starting with _time= 
anymore.  The _pad[] part I understand, but not the _x[] part, although I think 
that might have been a way to cause the evaluation to happen as I needed it to.
Within _cd, PS1 finally gets set as follows: if (( ${#PWD}  15 ))  
   thent1=${PWD%/*???}t2=${PWD#$t1/}
if (( ${#PWD}  ( ${#t2} + 3 ) ))then   
PS1=${label}$PS0...${t2}${p} else   
PS1=${label}$PS0$PWD${p} fi else
PS1=${label}$PS0$PWD${p}  fi
$label is (depending on the terminal type) an escape sequence to incorporate 
the hostname and current directory into the window title bar.  To keep that 
from confusing ksh’s idea of display column, it ends with a ^M.
It all works, but the ugliness is OTT.  There’s got to be a better way…

On Mar 12, 2015, at 8:51 AM, Janis Papanagnou janis_papanag...@hotmail.com 
wrote:To understand your situation...
You have already functional code?
Your code works but it has a performance problem building the PS1 prompt?
If you want something cleaner and faster it would help if you post your 
code so that we see where you are.


 From: rlham...@gmail.com
 Date: Thu, 12 Mar 2015 08:20:42 -0400
 To: ast-users@lists.research.att.com
 Subject: [ast-users] how to get functionality of bash compatible PS1 without  
 rest of bash compatibility?
 
 Yep, that was the question: more or less bash-compatible PS1 handling without 
 the rest of bash compatibility. I like timestamps and other odd things 
 (shortened directory) in my prompt, but I’d rather do it without enabling any 
 more bash compatibility than that. I’ve got some odd code that even I no 
 longer understand that gives the output I want, but it’s very ugly (certainly 
 not using a get discipline or anything like that, but computing a date having 
 determined an offset to apply to SECONDS to count since midnight). Something 
 cleaner and faster might be nice.
 
 ___
 ast-users mailing list
 ast-users@lists.research.att.com
 http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


[ast-users] Order of arguments significant with heredocs and process substitution?

2015-01-02 Thread Janis Papanagnou
Is the error in case 4 intentional behaviour...?


# case 1 - okay
cat - EOT |
...
EOT
awk '1' ( ... ) -


# case 2 - okay
awk '1' ( ... ) - EOT
...
EOT


# case 3 - okay
awk '1' ( ... ) EOT -
...
EOT


# case 4 - error: `)' unexpected
awk '1'  EOT ( ... ) -
...
EOT


# case 5 - okay
print ...  infile
awk '1'  EOT infile -
...
EOT


Observed with version sh (ATT Research) 93t+ 2010-03-05
Is this inconsistency fixed in newer versions of ksh (or is it intentional 
behaviour)?

Thanks!

  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] making wildcards safer

2014-07-12 Thread Janis Papanagnou
You are asking:
 Has this already been considered and rejected for reasons of which I'm 
 unaware, or does it sound reasonable to others?

As far as a quick view over the linked document can show I have
got the impression that the mentioned problems arise where '--'
is not used (or not available?) when using commands to mark the
'end of options'.

When you're unsure about what files are or can be present in your
processed directories you should place a '--' after the option list
and before the wildcards appear.

From the POSIX Utility Guidelines:
Guideline 10:The first -- argument that is not an option-argument should be 
accepted as a delimiter indicating the end of options.
Any following arguments should be treated as operands, even if they begin with 
the '-' character.


 From: rlham...@gmail.com
 Date: Fri, 11 Jul 2014 21:39:32 -0400
 To: ast-users@lists.research.att.com
 Subject: [ast-users] making wildcards safer
 
 I recently read
 http://www.defensecode.com/public/DefenseCode_Unix_WildCards_Gone_Wild.txt
 
 and although I was not unaware of these possibilities, the reminder was 
 nonetheless uncomfortable.
 
 It occurred to me that most abuses of wildcards with filenames that a command 
 might interpret as something other than a filename can be prevented by 
 preceding any wildcard that starts with a metacharacter with ./.
 
 It is not impossible to train oneself to type ./* instead of *...but it's 
 not particularly easy, either.
 
 It then occurred to me that it would be great to have a shell option 
 something like
 
 set -o saferexpand
 
 which would do just that: precede any results of the expansion of a wildcard 
 whose first character was a metacharacter with ./.
 
 For compatibility, it should be an option; and for the immediate future, not 
 the default.
 
 Has this already been considered and rejected for reasons of which I'm 
 unaware, or does it sound reasonable to others?
 
 
 ___
 ast-users mailing list
 ast-users@lists.research.att.com
 http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] A real number arithmetic issue

2014-07-03 Thread Janis Papanagnou
I have to followup on my own post from last week.

The proposed new version of ksh that I installed has a horrible
side effect when using the interactive history functions in vi
mode; misplacing the cursor, displaying control code, and
thus making it impossible to use. (I'm working on 64 bit Linux.)
Has someone observed a similar behaviour?

I switched back to the 2010 version and the history fine again;
modulo that real number bug - but I can do arithmetic using
other tools, still better than a spoiled history function.


From: janis_papanag...@hotmail.com
To: ast-users@lists.research.att.com
Date: Fri, 27 Jun 2014 10:58:28 +0200
Subject: Re: [ast-users] A real number arithmetic issue




Yes, indeed, four years is obviously too old. :-)

I downloaded the binary from http://www2.research.att.com/sw/download/
and can confirm your results from the test case.

Just wondered that the latest precompiled binary for a standalone ksh is
also quite old (2012-08-06  BASE  linux.i386-64); is above download link
still valid? - I noticed you are using a 2014 version.

Thanks!

Date: Thu, 26 Jun 2014 14:48:27 -0400
Subject: Re: [ast-users] A real number arithmetic issue
From: dgk...@gmail.com
To: janis_papanag...@hotmail.com; ast-users@lists.research.att.com

I suspect that this is because you are running a very old ksh93.  Here is what 
I get on ubuntu linux x86_63.13.0-30-generic4  release .
[...]

On Wed, Jun 25, 2014 at 3:59 PM, Janis Papanagnou 
janis_papanag...@hotmail.com wrote:




I've just noticed something strange with real number arithmetic in ksh.
The problem:
It seems that the fractional part in a division is interpreted as integer.


[...]


All done in the LC_ALL=C locale. On a Linux 2.6 platform.


Am I doing something wrong or is this some shell issue? 


Thanks!

  

___

ast-users mailing list

ast-users@lists.research.att.com

http://lists.research.att.com/mailman/listinfo/ast-users



  

___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


[ast-users] A real number arithmetic issue

2014-06-25 Thread Janis Papanagnou
I've just noticed something strange with real number arithmetic in ksh.
The problem:
It seems that the fractional part in a division is interpreted as integer.

$ print $(( log(2.171828) ))
0.775569209249095711

$ print $(( log(200.0) / log(2.171828) ))
ksh:  log(200.0) / log(2.171828) : divide by zero

$ print $(( log(200.0) / log(2) ))
ksh:  log(200.0) / log(2) : divide by zero

$ print $(( log(200.0) / log(3) ))
14

$ typeset -F a=200
$ typeset -F b=2.71828
$ print $(( log(a) / log(b) ))
ksh:  log(a) / log(b) : divide by zero

$ print $a $b
200.00 2.718280


$ typeset -F b=3.0
$ print $(( log(a) / log(b) ))
14

$ printf %f\n $(( log(a) / log(b) ))
14.00

$ typeset -F b=3.1
$ printf %f\n $(( log(a) / log(b) ))
14.00


$ ksh --version
  version sh (ATT Research) 93t+ 2010-03-05

All done in the LC_ALL=C locale. On a Linux 2.6 platform.


Am I doing something wrong or is this some shell issue? 

Thanks!

  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Strange printf %T behaviour

2014-04-05 Thread Janis Papanagnou
 From: iszczesn...@gmail.com
 To: janis_papanag...@hotmail.com
 CC: ast-us...@research.att.com; glenn.s.fow...@gmail.com
 
 On Sat, Apr 5, 2014 at 12:24 PM, Janis Papanagnou
 janis_papanag...@hotmail.com wrote:
  Please note the empty output lines of commands that previously showed
  output...
 
  $ printf %(%Z)T\n
  CEST
  $ TZ=GMT printf %(%Z)T\n
  GMT
  $ printf %(%Z)T\n
  CEST
  $ TZ= printf %(%Z)T\n
 
  $ printf %(%Z)T\n
 
  $ TZ=UTC printf %(%Z)T\n
 
  $ printf %(%Z)T\n
 
  $ TZ=GMT printf %(%Z)T\n
 
  $ printf %(%Z)T\n
 
 
  Version JM 93t+ 2010-03-05 (on Linux 2.6.32)
 
  Is that a bug in the (old) ksh version I use, and fixed in the current one?
 
 Random thought: Any printf %argument requires an argument to be
 passed, so you want
 printf '%T' now
 instead of
 print '%T'

Good point. But sadly adding 'now' doesn't change behaviour.
Once the shell is in the no-output state it stays there without
further output.

 
 Irek
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Configuring what goes into the history file

2014-01-03 Thread Janis Papanagnou
Omitting immediate duplicates as default seems reasonable to me.
It would be simple, and need no additional external controls. Nice.

Defining the beaviour through some means (env var or something)
would allow more control variants; like omitting duplicates even if
not adjacent in the file - the latter needs some more sophisticated
implementation though. Or allow extensions to any of zsh's options
(if considered useful).

Beyond no immediate duplicates and no duplicates at all I'd have
no need, but others might have, and it might be good to not rule out
other options.


Date: Fri, 3 Jan 2014 17:35:50 -0500
From: dgk...@gmail.com
To: e...@horch.org
CC: ast-users@lists.research.att.com
Subject: Re: [ast-users] Configuring what goes into the history file

Since all HISTCONTROL does is eliminate immediate duplicates or no keep 
commands that start with a space, I don't know why this can't be the default 
behavior.
Ignoring failed commands seems like a bad idea.  Failed command often occur 
because of a typo and in this case I want to edit the failed command.


On Thu, Jan 2, 2014 at 8:47 PM, Ed Horch e...@horch.org wrote:

What bash does is a good start.  I've always wanted a more powerful way to 
exclude certain things from the command history, especially erroneous and 
failed commands.  I haven't been able to think of a good way to specify that.  
For example:




$ cat ~/.kshcr
cat: /home/ebh/.kshcr: No such file or directory

That shouldn't go into the history.  But what about:

$ cat ~/.kshrc
cat: /home/ebh/.kshrc: No such file or directory



$ echo 'alias l=ls\ -xF' ~/.kshrc
$ # Would like to do M-PM-P here

Maybe some keep-previous-command-anyway editing function or some such.



-Ed Horch


___

ast-users mailing list

ast-users@lists.research.att.com

http://lists.research.att.com/mailman/listinfo/ast-users





___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Configuring what goes into the history file

2014-01-02 Thread Janis Papanagnou
Subject: Configuring what goes into the history file.

Yes, Ed, probably (I haven't checked bash). And I think zsh has something as 
well.
But I am specifically asking for ksh, since that is the shell I mostly use.
So I suppose there's no such feature in ksh? (And hardly a workaround, I guess.)

@David: Are there any plans to incorporate such a feature?


From: e...@horch.org
Date: Thu, 2 Jan 2014 16:48:39 -0500
To: ast-users@lists.research.att.com
Subject: Re: [ast-users] Configuring what goes into the history file

That sounds like what bash's HISTCONTROL variable does.

-Ed Horch


___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Bad math for right shift () 64 bits?

2013-12-30 Thread Janis Papanagnou

Interested in the behaviour I tried that with my version (Version JM 93t+ 
2010-03-05( and it gives the same result.
Moreover I noticed that in

integerb=$((2**32)) ; for ((i=0;i=97;i++)) ; do printf %5d\t%12d\n $i 
$(( b  i )) ; done
typeset -i b=$((2**32)) ; for ((i=0;i=97;i++)) ; do printf %5d\t%12d\n $i 
$(( b  i )) ; done

the first command produce the same result that you showed, while the second 
one produces only zeroes.
Moreover, if I run the second command first (and get the zeroes), then run the 
first command I get also zeroes, and if I rund the second command a second 
time it produces the result you observed.

Sorry, I meant if I run the _first_ command a second time:


$ typeset -i b=$((2**32)) ; for ((i=31;i=33;i++)) ; do printf %5d\t%12d\n $i 
$(( b  i )) ; done
   31   0
   32   0
   33   0
$ integerb=$((2**32)) ; for ((i=31;i=33;i++)) ; do printf %5d\t%12d\n $i 
$(( b  i )) ; done
   31   0
   32   0
   33   0
$ integerb=$((2**32)) ; for ((i=31;i=33;i++)) ; do printf %5d\t%12d\n $i 
$(( b  i )) ; done
   31   2
   32   1
   33   0

So there even seems to be a dependency to some internal shell state.


  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Raw command substitution $()

2013-12-16 Thread Janis Papanagnou
Can you exclude any character from your input data to be used as a separator?
Then you could redefine the read separator (in the example below I used X):

  printf \n\n\n\n\n | IFS= read -dX FOO


Date: Mon, 16 Dec 2013 21:02:01 +
From: eschulm...@bloomberg.net
To: AST-USERS@LISTS.RESEARCH.ATT.COM
Subject: [ast-users] Raw command substitution $()

Hi guys,I'm looking for a method to do raw command substitution.
The issue:- Need a ksh93t+ / ksh93u facillity to be able to take the literal 
output of a command with no substitutions or omissions, where the substitute 
data is less than 1kB.  Target platforms are RHEL 6.4, Solaris 11  AIX 7.1.
Examples.   printf is used below for illustration only.- $(), command 
substitution, i.e. FOO=$(printf \n\n\n\n\n);  seems unsuitable as it modifies 
the output by performing some whitespace handling, such as stripping newlines.  
In this example, FOO returns zero-length.- $(), quoted, prevents the field 
splitting and pathname expansions, but doesn't protect the trailing 
whitespace.- Binary read, i.e.   printf \n\n\n\n\n | read -N$length FOO;   
works provided the $length of the read doesn't encounter the EOF, in this case 
values 1-5.  If $length5, in this example, FOO becomes zero-length.  For an 
input of unknown length, this feels impractical.- One possible workaround is 
adding a suffix and then chopping it, i.e.  FOO=$(printf 
\n\n\n\n\nmysuffix); FOO=${FOO%mysuffix}
Any advice on the best way to acquire the literal command output?
Thanks!-G
___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] operations on an entire array

2013-12-13 Thread Janis Papanagnou
Probably not as compact as you'd wish...

$ x=( 1 2 3 4 5 6 7 8 9 10 )
$ echo $(( $( printf +%d ${x[@]} ) ))
55


 From: joshua.tay...@sub-verses.org
 Date: Fri, 13 Dec 2013 14:53:24 +0100
 To: ast-users@lists.research.att.com
 Subject: [ast-users] operations on an entire array
 
 I was wondering if there is some syntax or some method to perform an 
 operation (the same operation) on all elements of an array.
 
 for example:
 
 x=( 1 2 3 4 5 6 7 8 9 10 )
 
 is there a shortcut to this:
 ((x[0]+x[1]+x[2]+x[3] ... )) as well as avoiding a for loop?
 
 I had imagined something like x[@]+
 
 Of course, if not, i’ve always got the classic:
 for i in ${x[@]}
 do
 (( total=total+i ))
 done
 ___
 ast-users mailing list
 ast-users@lists.research.att.com
 http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Question about the nounset option

2013-10-16 Thread Janis Papanagnou
I understand the OP considering that clumsy. And something being defined
by POSIX doesn't prevent it being clumsy or not defined in an optimal way;
sometimes even the opposite is true. But I'd rather like to abstain from such
flame-prone valuations and consider the given application.
@Axel: I'm not sure your sample is only test code. If so, you can trigger the
effecte more simply (without if condition) by /bin/ksh -uc 'echo ${TESTVAR}'.
Otherwise I'd use the less clumsy /bin/ksh -uc 'echo ${TESTVAR-undefined}
(without if, but still with the default value substitution).
Part of the clumsiness in your sample stems from the explicit if test and the
implicit test in ${v- }; one can be avoided.

Janis


 Date: Wed, 16 Oct 2013 14:23:57 +0200
 From: lionelcons1...@gmail.com
 To: axel.phil...@mtu.de
 CC: ast-us...@research.att.com
 Subject: Re: [ast-users] Question about the nounset option
 
 On 16 October 2013 09:14, PHILIPP, Axel, Dr. axel.phil...@mtu.de wrote:
  I wonder whether it is desirable that test -n and test -z trigger the unset 
  error condition:
 
  /bin/ksh -uc 'if [[ -n $TESTVAR ]]; then echo $TESTVAR; else echo 
  undefined; fi'
  /bin/ksh: TESTVAR: parameter not set
 
  I know all shells from the sh family I have tested behave this way, but I 
  would prefer a solution (additional option or env var) that the error is 
  not triggered in these test cases.
 
 You can use [[ -v TESTVAR ]] to test whether a variable does exists or
 not. This uses the variables name (TESTVAR) and not the value
 ($TESTVAR).
 
 
  The obvious workaround is somewhat clumsy:
  /bin/ksh -uc 'if [[ -n ${TESTVAR-} ]]; then echo $TESTVAR; else echo 
  undefined; fi'
  undefined
 
 Why is this clumsy? This is how POSIX sh was designed and everyone
 uses as designed. Why is this a problem?
 
 Lionel
 ___
 ast-users mailing list
 ast-users@lists.research.att.com
 http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Arithmetic assignment side-effects

2013-08-06 Thread Janis Papanagnou
  
  Go strictly from left to right.
 
 How do you assign something that hasn't been evaluated yet? Evaluating the 
 expression on the RHS is an absolute prerequisite to evaluating the 
 assignment 
 itself. (x += x) = 1 is nonsense. It evaluates to 0 = 1.

It makes sense, depending on the language. With LVALUE=RVALUE and
LVALUE+=LVALUE, where the result is an LVALUE, consider it evaluated as

(ref(x) = deref(x)+deref(x)) = 1

(Try your expression above in C++, for example. It works as expected.)

Nonetheless right to left parsing seems the only sensible semantics in
case of = and op= assignments.

Janis

 
[...]
 
 I've also already proven that at least in ksh it goes right to left, because 
 if you define a setter property to trigger a side-effect for each variable, 
 the RHS fires before the LHS of the +=.
 
 There's just no amount of mind-bending I can think of that could make 
 evaluating the += first produce anything other than an error.
 -- 
 Dan Douglas
 ___
 ast-users mailing list
 ast-users@lists.research.att.com
 http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Arithmetic assignment side-effects

2013-08-06 Thread Janis Papanagnou
Oops. Should have been...





  (x += x) = 1 is nonsense. It evaluates to 0 = 1.

 It makes sense, depending on the language. With LVALUE=RVALUE and
 LVALUE+=LVALUE, where the result is an LVALUE, consider it evaluated as

LVALUE+=RVALUE

 (ref(x) = deref(x)+deref(x)) = 1

 (Try your expression above in C++, for example. It works as expected.)

 Nonetheless right to left parsing seems the only sensible semantics in
 case of = and op= assignments.
 
 Janis

  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Passing a file descriptor to a child process?

2013-07-29 Thread Janis Papanagnou
 From: tina.harriott.mathemat...@gmail.com
 On 29 July 2013 14:40, David Korn d...@research.att.com wrote:
  cc: tina.harriott.mathemat...@gmail.com
  Subject: Re: [ast-users] Passing a file descriptor to a child process?
  
 
 
  ksh93 uses O_CLOEXEC to avoid passing all its file descriptors to a
  child process. That is IMO a good thing (clean!).
 
  However, is there a way to pass a file descriptor to a child process?
 
  Tina
  --
  Tina Harriott  - Women in Mathematics
  Contact: tina.harriott.mathemat...@gmail.com
 
 
  Yes, run
  any_command {fd} foobar
 
  to open foobar for reading and pass it to an_command.
  exec {fd} foobar
  will open it only in the shell environment
 
 How can I keep the fd open for multiple commands in a sequence?

Command grouping...?

{ cmd1
  cmd2
}  {fd} foobar


Janis

 
 Tina
 -- 
 Tina Harriott  - Women in Mathematics
 Contact: tina.harriott.mathemat...@gmail.com
 ___
 ast-users mailing list
 ast-users@lists.research.att.com
 http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Edit 10GB file with fixed size records

2013-07-26 Thread Janis Papanagnou
  Does ksh have an API to edit a file at a specific position pos1, read
  n1 bytes, and write n1 bytes at that position without truncating the
  file? I need this to do edit a file in place without reading and
  writing it completely each time.
 
  Yes, ksh has seek redirection operators.
 
[snip]
 
 
  read -N $n1 content 0$f #((pos1))
  printf %s $(fun $content) 1$f #((pos1))
 

[snip]
 
 How would this example look like if I opened a file descriptor with
 the number 19? ksh seems to use file descriptors 0-9 for manual usage,
 but descriptors opened with exec {filed}name.rec use numbers  10.

I'd have thought by prepending {filed} to the seek redirections;
  {filed}#((pos1))  and  {filed}#((pos1))  respectively.
Doesn't that work?

Janis

 
 Tina
 -- 
 Tina Harriott  - Women in Mathematics
 Contact: tina.harriott.mathemat...@gmail.com
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Can't pass parameters to an instance constructor

2013-07-16 Thread Janis Papanagnou

  
   Hi, here x.val is assigned after the constructor has already run. It 
   should
   be assigned before so it's accessiable to the create:
   
   typeset -T X=( integer val
   
   function create { ((_.val++)) })
   
   X x=(val=5) print -v x.val # should print 6
   
  
  ksh93 currently doesn't have a create discipline and you example doesn't
  invoke x.create so why should val be incremented?
 
 It's described within the TYPES document:

What is that document you mention and where can I find it?

And more generally; is there any detailled documentation of
ksh's new features besides the man page?

Thanks!

Janis

  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Check out my profile on LinkedIn

2013-07-15 Thread Janis Papanagnou
 I'm very sorry for this. This is what I got for trusting that Linkedin
 only contacts people with existing Linkedin profiles.

Your experience can be summarized...

Abandon all hope, ye who enter here. [Dante]


 Ced

  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] ksh88 vs 93 behavior re: hex numbers

2013-02-28 Thread Janis Papanagnou


With my ksh93 Version JM 93t+ 2010-03-05 I get what you expect

$ typeset -i16 HEX=16#ff
$ print $HEX
16#



 Date: Thu, 28 Feb 2013 18:43:52 -0800 
 From: patgeis...@gmail.com 
 To: ast-users@lists.research.att.com 
 Subject: [ast-users] ksh88 vs 93 behavior re: hex numbers 
  
 All, 
  
 Sorry if this is well-known but I searched through the list archives  
 and didn't 
 find anything on point. 
  
 In short, ksh93 is masking off the upper bits of my hex numbers where  
 ksh88 did not. 
 My question is, is this by design? A bug? A LOCALE issue? If it's  
 configurable, how 
 do I get the old behavior back? 
  
 ksh88 example: 
 % typeset -i16 HEX=16#ff 
 % print $HEX 
 16#ff 
  
 ksh93 example: 
 % typeset -i16 HEX=16#ff 
 % print $HEX 
 16#7fff  masked to lower 31-bits ... not what I want! 
 __ 
 Patrick 
  
 ___ ast-users mailing list  
 ast-users@lists.research.att.com  
 http://lists.research.att.com/mailman/listinfo/ast-users 
  
___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] [ksh93] interactive ksh always exits 0 on CTRL-D

2012-12-06 Thread Janis Papanagnou

 Subject: Re: [ast-users] [ksh93] interactive ksh always exits 0 on CTRL-D
 

  Not a big problem but I think it better exit $?.


 I tried the following and it did not exit 0.

 $ ksh
 $ false
 ^D
 $ print $?
 1

 David Korn
 d...@research.att.com

Do we need some specific ksh version to make that work?
Or does that just mean that the behaviour is undefined?

I am running ksh 93t+ 2010-03-05 and above sample as well
returns 0 here in my Ubuntu/Linux 2.6 environment.

(No traps set, BTW.)

  
___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users