Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How arrays are different in Solaris shell script

1,449 views
Skip to first unread message

mus...@gmail.com

unread,
Feb 1, 2009, 1:22:06 AM2/1/09
to
Hi gUruS,

Im trying to set a string variable to array using shell script it is
working fine with Hp-Ux but not with Solaris.

HP-UX
--------------------------
$ cat arr.sh

set -A myarray First Second Third
echo "myarray has ${#myarray[*]} elements."
echo "myarray contains: ${myarray[*]}"

$ sh arr.sh - OUTPUT
myarray has 3 elements.
myarray contains: First Second Third

---------------------------------------------------------------------------------

Solaris
----------------
OUTPUT -

arr.sh: -A: bad option(s)

-----------------------------------------------------------------------------------

Please help me with this ?

Michael Weis

unread,
Feb 1, 2009, 4:15:42 AM2/1/09
to

>
> Solaris
> ----------------
> OUTPUT -
>
> arr.sh: -A: bad option(s)
>
> -----------------------------------------------------------------------------------
>
> Please help me with this ?

Which shell? Try bash in Solaris, then it will work.

Michael

Chris Mattern

unread,
Feb 1, 2009, 9:31:56 AM2/1/09
to

Your HP-UX is apparently not supplying you with a true Bourne shell in
sh. This common in many Linuxes but is unusual for a commercial Unix. I
don't know HP-UX that well; what happens when you try "/usr/bin/sh arr.sh"
or "/bin/sh arr.sh"? Arrays aren't supported in Bourne shell, and when you
try to run it using Solaris's Bourne shell, it doesn't work, which is what
you'd expect. Try using Korn shell instead--/usr/bin/ksh.


--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities

Sven Mascheck

unread,
Feb 1, 2009, 11:34:43 AM2/1/09
to
Chris Mattern wrote:

> Your HP-UX is apparently not supplying you with a true Bourne shell in
> sh. This common in many Linuxes but is unusual for a commercial Unix.

No. In favour of POSIX shells, traditional Bourne shells are becoming
increasingly rare as system shell, although some systems keep them as
/bin/sh (probably to avoid migration issues with existing scripts/habits).

Nowadays, well known flavours with a Bourne shell are Solaris, OpenServer,
UnixWare/aka OpenUnix, Tru64 aka OSF1. You could add the sufficiently
old systems of other flavours which are still running somewhere.

Sidenote: HP-UX is one of the few flavours which even stopped shipping
the Bourne Shell at all (at a different path, for backwards compatibility).
--
http://www.in-ulm.de/~mascheck/various/shells/

Chris Mattern

unread,
Feb 1, 2009, 12:37:49 PM2/1/09
to

Okay. That's interesting to know about HP-UX. Well, that pretty much
covers it. Your difference here is that "sh" in HP-UX is not in fact the
same shell as "sh" in Solaris. In order to accomplish what you want to do
in Solaris, you need to use a shell that supports arrays. ksh should do well
for what you're trying to do. bash also supports arrays, but not with the
syntax you're using, so you'd have to rewrite.

da...@smooth1.co.uk

unread,
Feb 1, 2009, 3:10:26 PM2/1/09
to
On 1 Feb, 17:37, Chris Mattern <sys...@sumire.gwu.edu> wrote:

http://en.wikipedia.org/wiki/Korn_shell

"The Korn shell (ksh) is a Unix shell which was developed by David
Korn (AT&T Bell Laboratories)"

"Although the ksh93 version added many improvements (associative
arrays, floating point arithmetic, etc.), some vendors still ship
their own version of the older ksh88 as /bin/ksh, sometimes with
extensions (as of 2005[update] only Solaris and NCR UNIX (a.k.a. MP-
RAS) ship ksh88, all other Unix vendors migrated to ksh93 and even
Linux distributions started shipping ksh93). There are also two
modified versions of ksh93 which add features for manipulating the
graphical user interface: dtksh which is part of CDE and tksh which
provides access to the Tk widget toolkit."

I would get the ksh93 version from http://www.kornshell.com/software/
"AT&T has released KornShell as open source. Distributions of source
and binaries can be obtained through the AT&T website by downloading
the ast-ksh package. Click here to download from the AT&T web site."

That link leads to http://www.research.att.com/~gsf/cgi-bin/download.cgi?action=list&name=ast-ksh

Release notes are at http://www.research.att.com/~gsf/download/gen/ast-ksh.html#ksh93
changes

Chris Mattern

unread,
Feb 1, 2009, 3:54:15 PM2/1/09
to
On 2009-02-01, da...@smooth1.co.uk <da...@smooth1.co.uk> wrote:
> On 1 Feb, 17:37, Chris Mattern <sys...@sumire.gwu.edu> wrote:
>> On 2009-02-01, Sven Mascheck <masch...@email.invalid> wrote:
>>
>> > Chris Mattern wrote:
>>
>> >> Your HP-UX is apparently not supplying you with a true Bourne shell in
>> >> sh.  This common in many Linuxes but is unusual for a commercial Unix.
>>
>> > No. In favour of POSIX shells, traditional Bourne shells are becoming
>> > increasingly rare as system shell, although some systems keep them as
>> > /bin/sh (probably to avoid migration issues with existing scripts/habits).
>>
>> > Nowadays, well known flavours with a Bourne shell are Solaris, OpenServer,
>> > UnixWare/aka OpenUnix, Tru64 aka OSF1.  You could add the sufficiently
>> > old systems of other flavours which are still running somewhere.
>>
>> > Sidenote: HP-UX is one of the few flavours which even stopped shipping
>> > the Bourne Shell at all (at a different path, for backwards compatibility).
>>
>> Okay.  That's interesting to know about HP-UX.  Well, that pretty much
>> covers it.  Your difference here is that "sh" in HP-UX is not in fact the
>> same shell as "sh" in Solaris.  In order to accomplish what you want to do
>> in Solaris, you need to use a shell that supports arrays.  ksh should do well
>> for what you're trying to do.  bash also supports arrays, but not with the
>> syntax you're using, so you'd have to rewrite.
>>
<snip a bunch of stuff about ksh88 and ksh93>

Very interesting but not really relevant to his problem. The ksh88 that
ships with Solaris supports the array stuff he's doing.

Chris Mattern

unread,
Feb 1, 2009, 5:30:07 PM2/1/09
to
Actually, no, it won't, because he's using ksh array syntax. He wants to
use ksh if he doesn't want to rewrite his script. Fortunately, Solaris
ships with ksh.

Geoff Clare

unread,
Feb 2, 2009, 8:57:58 AM2/2/09
to
Chris Mattern wrote:

> Your difference here is that "sh" in HP-UX is not in fact the
> same shell as "sh" in Solaris.

There is more than one `"sh" in Solaris'. What you get when you
type "sh" depends on your PATH. For Solaris users who have set up
their PATH for standards conformance by doing something like

PATH=$(getconf PATH):other_dirs

when they type "sh" they will get /usr/xpg4/bin/sh, which is very
similar to HP-UX "sh". (They are both POSIX-ized versions of ksh88.)

--
Geoff Clare <net...@gclare.org.uk>

0 new messages