From owner-freebsd-questions@FreeBSD.ORG Tue Nov 29 21:29:26 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 7E03D16A41F; Tue, 29 Nov 2005 21:29:26 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail6.speedfactory.net [66.23.216.219]) by mx1.FreeBSD.org (Postfix) with ESMTP id B0BA743D8F; Tue, 29 Nov 2005 21:29:05 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.5b3) with ESMTP id 2827609 for multiple; Tue, 29 Nov 2005 16:28:49 -0500 Received: from localhost (john@localhost [127.0.0.1]) by server.baldwin.cx (8.13.1/8.13.1) with ESMTP id jATLSuFU074701; Tue, 29 Nov 2005 16:28:57 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Tue, 29 Nov 2005 16:17:15 -0500 User-Agent: KMail/1.8.2 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511291617.16666.jhb@freebsd.org> X-Spam-Status: No, score=-2.8 required=4.2 tests=ALL_TRUSTED autolearn=failed version=3.0.2 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on server.baldwin.cx X-Server: High Performance Mail Server - http://surgemail.com r=1653887525 Cc: Jayesh Jayan , 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:29:26 -0000 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=( 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 != 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="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" = http://www.FreeBSD.org