Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Sep 2000 10:54:27 -0700 (PDT)
From:      "Duane H. Hesser" <dhh@androcles.com>
To:        Randall Hopper <aa8vb@nc.rr.com>
Cc:        freebsd-stable@FreeBSD.ORG, Gregory Bond <gnb@itga.com.au>
Subject:   Re: "set -A" Bourne script - a nogo on FreeBSD
Message-ID:  <XFMail.000916105427.dhh@androcles.com>
In-Reply-To: <20000915211957.A1285@nc.rr.com>

next in thread | previous in thread | raw e-mail | index | archive | help

"set -A' is ksh's method for declaring an array.  The "real"
Bourne shell does not support arrays (hence no way to declare them).

Frequently, /bin/sh is not a "real" Bourne shell, rather some other
shell (bash, zsh, ksh) emulating the Bourne shell (e.g. /bin/sh is
usually "bash" on linux).

Bash and zsh, when called as 'sh', try to dumb themselves down to
look like the Bourne shell, but the "dumbing down" is imperfect, and
neither of them disables support for arrays.

Bash (even when running as 'sh') will declare arrays using 'typset -a'
(or declare -a); zsh declares arrays with 'typeset -A'. Ksh declares
arrays with 'set -A', and associative arrays with 'typeset -A'.

Some systems install ksh88 as /bin/sh, but so far as I know, it does
not behave differently (i.e. attempt to emulate 'sh').  Usually the
manual page will alert you to this.

All of the above shells will allow declaring an array implicitly, in
the 'csh' style, with something like

wombat=( 1 2 3 4 5 )

All of the shells except 'zsh' use array indices starting with '0';
zsh array indices start with '1' (unless it's running in 'ksh'
emulation mode).

You may be able to identify the shell using 'set | grep VERSION';
bash sets BASH_VERSION, zsh sets ZSH_VERSION, and the pd emulation
of ksh sets KSH_VERSION.  Otherwise, if it has arrays, it is probably
ksh88 or ksh93.

ksh93 can be identified by 'echo ${.sh.version}'.

I have no idea how to ID ksh88 (it's been too long), but if the shell
supports arrays, and isn't one of the above, it's probably ksh88.

Ksh93 has only recently gone "open-source", so the likelihood is that
the IRIX shell is ksh88 (just a guess).
 
On 16-Sep-00 Randall Hopper wrote:
> Gregory Bond:
>  |> Seems FreeBSD's Bourne shell's "set" command doesn't support -A.
>  |
>  |AFAICT "set -A" is a ksh-ism, not a bourne-ism.  On my Solaris systems, ksh 
>  |has "set -A", but neither bash nor sh do.  Install one of the ksh verisions 
>  |from the ports.
> 
> Ok, maybe it isn't a universal Bourne-ism then.
> 
> Reason I asked is my /bin/sh on IRIX at work has set -A.
> 
> -- 
> Randall Hopper
> aa8vb@nc.rr.com
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-stable" in the body of the message
> 

--------------
Duane H. Hesser
dhh@androcles.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.000916105427.dhh>