Date: Wed, 6 Feb 2002 13:47:24 +0100 From: messmate <messmate@free.fr> To: freebsd-questions-en <freebsd-questions@FreeBSD.org> Subject: Re: Stupid sh(1) question Message-ID: <20020206134724.4d8fa6a7.messmate@free.fr> In-Reply-To: <20020206115755.GA8768@teddy.fas.com> References: <20020204154923.GA4312@rhadamanth> <a3merr$1biv$1@kemoauc.mips.inka.de> <20020206115755.GA8768@teddy.fas.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Bash do it : (if your shell is the Bourne Shell) #!/bin/bash area[11]=23 area[13]=37 area[51]=UFOs # Array members need not be consecutive or contiguous. # Some members of the array can be left uninitialized. # Gaps in the array are o.k. echo -n "area[11] = " echo ${area[11]} # {curly brackets} needed echo -n "area[13] = " echo ${area[13]} echo "Contents of area[51] are ${area[51]}." # Contents of uninitialized array variable print blank. echo -n "area[43] = " echo ${area[43]} echo "(area[43] unassigned)" echo # Sum of two array variables assigned to third area[5]=`expr ${area[11]} + ${area[13]}` echo "area[5] = area[11] + area[13]" echo -n "area[5] = " echo ${area[5]} area[6]=`expr ${area[11]} + ${area[51]}` echo "area[6] = area[11] + area[51]" echo -n "area[6] = " echo ${area[6]} # This fails because adding an integer to a string is not permitted. echo; echo; echo # etc..... mess-mate On Wed, 6 Feb 2002 06:57:55 -0500 stan <stanb@awod.com> wrote: | On Mon, Feb 04, 2002 at 05:02:51PM +0000, Christian Weisgerber wrote: | > Ceri <setantae@submonkey.net> wrote: | > | > > Now, I _have_ read the manpage, but I cannot work out : | > > a) How to initialise an array in sh | > > b) How to access an array in sh. | > | > sh doesn't support arrays. | > | ksh, however does. | | -- | "They that would give up essential liberty for temporary safety deserve | neither liberty nor safety." | -- Benjamin Franklin | | To Unsubscribe: send mail to majordomo@FreeBSD.org | with "unsubscribe freebsd-questions" in the body of the message | To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020206134724.4d8fa6a7.messmate>