Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Nov 2005 03:21:46 +0530
From:      Jayesh Jayan <jayesh.freebsdlist@gmail.com>
To:        Wesley Shields <wxs@csh.rit.edu>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Bash scripting -- Usage of arrays
Message-ID:  <e8ecf3c00511291351s1f9164a6pe9c4ad938e24d1e7@mail.gmail.com>
In-Reply-To: <20051129213252.GA68141@csh.rit.edu>
References:  <e8ecf3c00511291309yb9caeb9uebdf92c4ad7af4f8@mail.gmail.com> <20051129213252.GA68141@csh.rit.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Wesley,

Thank you.

I understood it completely.

The explanation was great.

Thank you once again.


On 11/30/05, Wesley Shields <wxs@csh.rit.edu> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e8ecf3c00511291351s1f9164a6pe9c4ad938e24d1e7>