From owner-freebsd-questions@FreeBSD.ORG Tue Nov 29 21:31:36 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 A3C2E16A41F for ; Tue, 29 Nov 2005 21:31:36 +0000 (GMT) (envelope-from wxs@syn.csh.rit.edu) Received: from syn.csh.rit.edu (syn.csh.rit.edu [129.21.60.158]) by mx1.FreeBSD.org (Postfix) with ESMTP id 248F043D4C for ; Tue, 29 Nov 2005 21:31:20 +0000 (GMT) (envelope-from wxs@syn.csh.rit.edu) Received: from syn.csh.rit.edu (localhost [127.0.0.1]) by syn.csh.rit.edu (8.13.3/8.13.1) with ESMTP id jATLWqaW068466; Tue, 29 Nov 2005 16:32:52 -0500 (EST) (envelope-from wxs@syn.csh.rit.edu) Received: (from wxs@localhost) by syn.csh.rit.edu (8.13.3/8.13.1/Submit) id jATLWqnC068465; Tue, 29 Nov 2005 16:32:52 -0500 (EST) (envelope-from wxs) Date: Tue, 29 Nov 2005 16:32:52 -0500 From: Wesley Shields To: Jayesh Jayan Message-ID: <20051129213252.GA68141@csh.rit.edu> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.11 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:31:36 -0000 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=( 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=( 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