Operating System - HP-UX
1754282 Members
2866 Online
108813 Solutions
New Discussion юеВ

Re: difference between ksh and POSIX sh: assigning SECONDS[1] quits

 
Jdamian
Respected Contributor

difference between ksh and POSIX sh: assigning SECONDS[1] quits

I've found this different behaviour of ksh and POSIX sh:

ksh quits the shell (or session) if an element of a *special* shell variable is tried to be initalized. "*special* shell variable" means shell variable updated internally by shell as SECONDS, RANDOM or _. Try

RANDOM[2]=45

Instead, POSIX sh allows these *special* shell variables to be arrays as ordinary variables and does not quit.

I've found a similar behaviour in Korn shell for Solaris.
4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: difference between ksh and POSIX sh: assigning SECONDS[1] quits

This still aborts on 11.31. Have you contacted the Response Center? Here is a stack trace:
#0 0x0 in
#1 0x40531d0:0 in nam_putval+0x8b0
#2 0x403bf00:0 in env_namset+0x620
#3 0x403b840:0 in env_setlist+0xe0
#4 0x40379a0:0 in sh_exec+0x760
#5 0x4035170:0 in exfile+0x970
#6 0x4033ac0:0 in main+0xa50

Any reason you are trying to do that?
If you insist, you can simply unset the variable first.
Peter Nikitka
Honored Contributor

Re: difference between ksh and POSIX sh: assigning SECONDS[1] quits

Hi,

in ksh it is always recommended to declare arrays explicitly - whether you use a predefined variable or not.

root@hp1[192] set -A SECONDS
root@hp1[193] SECONDS[2]=aa
root@hp1[194] print ${SECONDS[2]}
aa
root@hp1[195] print ${#SECONDS[*]}
1
root@hp1[196] uname -a
HP-UX hp1 B.11.23 U ia64 2944899503 unlimited-user license

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Jdamian
Respected Contributor

Re: difference between ksh and POSIX sh: assigning SECONDS[1] quits

Hi Peter


Try using the variable _ instead of SECONDS.
Peter Nikitka
Honored Contributor

Re: difference between ksh and POSIX sh: assigning SECONDS[1] quits

Hi Oscar,

at least for this SUN-Solaris this is NOT true (no HP-UX at hand today):

ef3nip00@malt uname -a
SunOS malt 5.10 Generic_118833-36 sun4u sparc SUNW,Sun-Fire-280R
ef3nip00@malt set -A _ aa bb cc
ef3nip00@malt echo ${_[0]}
aa

and even (in a new ksh) this works:
ef3nip00@malt echo $_
/usr/bin/ksh
ef3nip00@malt _[1]=hu
ef3nip00@malt echo ${_[*]}
/usr/bin/ksh hu

You could file a bug report - the docs tell us, that those variables loose their special meaning when manually modified, but there is no limitation on the type of the modifaction.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"