From owner-freebsd-questions Wed Feb 6 5: 9:30 2002 Delivered-To: freebsd-questions@freebsd.org Received: from postfix1-2.free.fr (postfix1-2.free.fr [213.228.0.130]) by hub.freebsd.org (Postfix) with ESMTP id F3ACE37B41C for ; Wed, 6 Feb 2002 05:09:26 -0800 (PST) Received: from localhost.localdomain (lille-2-a7-4-246.dial.proxad.net [62.147.4.246]) by postfix1-2.free.fr (Postfix) with SMTP id 6F55CAB378 for ; Wed, 6 Feb 2002 14:09:25 +0100 (CET) Date: Wed, 6 Feb 2002 13:47:24 +0100 From: messmate To: freebsd-questions-en 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> <20020206115755.GA8768@teddy.fas.com> X-Mailer: Sylpheed version 0.7.0 (GTK+ 1.2.10; i586-mandrake-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 wrote: | On Mon, Feb 04, 2002 at 05:02:51PM +0000, Christian Weisgerber wrote: | > Ceri 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