From owner-freebsd-questions@FreeBSD.ORG Tue Nov 29 21:51:59 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 A0C5216A42C for ; Tue, 29 Nov 2005 21:51:59 +0000 (GMT) (envelope-from jayesh.freebsdlist@gmail.com) Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.194]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3964A43D75 for ; Tue, 29 Nov 2005 21:51:46 +0000 (GMT) (envelope-from jayesh.freebsdlist@gmail.com) Received: by xproxy.gmail.com with SMTP id t12so80298wxc for ; Tue, 29 Nov 2005 13:51:46 -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=sl0Ai7InUeaX3s4VeEBeC1IUBLBvRL0oNRmpAXv3JY8BcUdVDvlTz+k0Uqrk6QQY73VNlMR7LRvNP6eGdnpiSnYwc7GMF+Ou96VU+Xef0R9qYoeeZ2NFpmRwzLOhy9+BnHTgafZ05UhLO0JoiJZSkvntmbVEmvS9WLlyPYdud1Q= Received: by 10.70.15.4 with SMTP id 4mr4266064wxo; Tue, 29 Nov 2005 13:51:46 -0800 (PST) Received: by 10.70.7.2 with HTTP; Tue, 29 Nov 2005 13:51:46 -0800 (PST) Message-ID: Date: Wed, 30 Nov 2005 03:21:46 +0530 From: Jayesh Jayan To: Wesley Shields In-Reply-To: <20051129213252.GA68141@csh.rit.edu> MIME-Version: 1.0 References: <20051129213252.GA68141@csh.rit.edu> 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-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:52:00 -0000 Hi Wesley, Thank you. I understood it completely. The explanation was great. Thank you once again. On 11/30/05, Wesley Shields wrote: > > On Wed, Nov 30, 2005 at 02:39:15AM +0530, 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. > > Bash (installed via ports) is in /usr/local/bin. Change the first line > to be #!/usr/local/bin/bash and chmod 750 (at least) the script. This > way you can just ./aa.sh and be done. > > If you prefer to run it as you have shown above don't run sh aa.sh, > instead do bash aa.sh, assuming bash is in your path. sh aa.sh will try > and run the script through sh (which is not bash). > > wxs@syn ~ > ls -la foo.sh > -rwxr-xr-x 1 wxs wxs 97 Nov 29 16:26 foo.sh* > wxs@syn ~ > cat foo.sh > #!/usr/local/bin/bash > > array=3D( zero one two three four); > echo "Elements in array0: ${array[@]}" > wxs@syn ~ > bash ./foo.sh > Elements in array0: zero one two three four > wxs@syn ~ > ./foo.sh > Elements in array0: zero one two three four > wxs@syn ~ > sh ./foo.sh > ./foo.sh: 3: Syntax error: word unexpected (expecting ")") > wxs@syn ~ > > > -- WXS > -- Jayesh Jayan "The box said "Requires Windows 95, NT, or better", so I installed Linux." Visit my homepage @ http://www.jayeshjayan.com