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 ?
Which shell? Try bash in Solaris, then it will work.
Michael
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
> 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/
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.
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
Very interesting but not really relevant to his problem. The ksh88 that
ships with Solaris supports the array stuff he's doing.
> 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>