From owner-freebsd-questions@FreeBSD.ORG Tue Nov 29 21:50:48 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6BA9616A41F for ; Tue, 29 Nov 2005 21:50:48 +0000 (GMT) (envelope-from jayesh.freebsdlist@gmail.com) Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.205]) by mx1.FreeBSD.org (Postfix) with ESMTP id 33A8643D4C for ; Tue, 29 Nov 2005 21:50:44 +0000 (GMT) (envelope-from jayesh.freebsdlist@gmail.com) Received: by xproxy.gmail.com with SMTP id t12so80020wxc for ; Tue, 29 Nov 2005 13:50:42 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=Z5S9ZedX3b1u/WPFQQzoyK/puqhT28zdJLvKZQxi1daXgRC3u46OR/M5A6Tf7Kl08g3vXA9J/FAp/dF1X6TNfmr3PgG5vYzSemBueatJfD9J4kMeqBQ+jNyHsWGPKx1c9e2VtkFwNzw204eoWNLIiuQ+gptjOJkYVxKNZSn32lw= Received: by 10.70.12.9 with SMTP id 9mr2728824wxl; Tue, 29 Nov 2005 13:50:42 -0800 (PST) Received: by 10.70.7.2 with HTTP; Tue, 29 Nov 2005 13:50:42 -0800 (PST) Message-ID: Date: Wed, 30 Nov 2005 03:20:42 +0530 From: Jayesh Jayan To: John Baldwin In-Reply-To: <200511291617.16666.jhb@freebsd.org> MIME-Version: 1.0 References: <200511291617.16666.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-hackers@freebsd.org, freebsd-questions@freebsd.org Subject: Re: Bash scripting -- Usage of arrays X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Nov 2005 21:50:48 -0000 Hi John, Thank you. It seems to work like a charm. On 11/30/05, John Baldwin wrote: > > On Tuesday 29 November 2005 04:09 pm, Jayesh Jayan wrote: > > Hi, > > > > Today I was trying to script using arrays in FreeBSD 5.4 but it doesn't > > work. > > > > Below is a sample script which I used. > > > > ****************************************************** > > > > #!/bin/bash > > > > array=3D( zero one two three four); > > echo "Elements in array0: ${array[@]}" > > > > ****************************************************** > > > > It works fine on RedHat server. > > > > Below is the output. > > > > # sh array.sh > > Elements in array0: zero one two three four > > > > Below is the out put from the FreeBSD server using the same code. > > > > -bash-2.05b# sh aa.sh > > aa.sh: 3: Syntax error: word unexpected (expecting ")") > > > > Please guide me on how to use arrays on freebsd too. > > sh !=3D bash > > You can either install bash from ports, or you can write your scripts in > sh > without using bash extensions. For example, with sh you can do things > like: > > array=3D"zero one to three four" > for x in $array; do > echo $x > done > > However, you can't easily get the count of items. You could maybe do > something like: > > set $array > echo "$# items" > > but that's somewhat hackish. > > -- > John Baldwin <>< http://www.FreeBSD.org/~jhb/ > "Power Users Use the Power to Serve" =3D http://www.FreeBSD.org > -- Jayesh Jayan "The box said "Requires Windows 95, NT, or better", so I installed Linux." Visit my homepage @ http://www.jayeshjayan.com