Bash Programming

Devin Whalen devin-Gq53QDLGkWIleAitJ8REmdBPR1lH4CV8 at public.gmane.org
Wed Aug 18 21:05:08 UTC 2004


On Wed, 2004-08-18 at 16:57, Chris F.A. Johnson wrote:
> On Wed, 18 Aug 2004, Devin Whalen wrote:
> 
> > Hey,
> >
> > I am new to bash programming so I don't know what is wrong with this
> > piece of code.  I am trying to create an array and loop through it:
> >
> > export_tables=( "table1" "table2" "table3" "table4" )
> > #export_tables[0]="hello"
> >
> >        for table in ${export_tables[@]};
> >                do
> >                  echo "$table"
> >                done
> 
>      It works for me in both Mandrake Linux and FreeBSD.
> 
>      Are you sure you're executing it with bash?
> 
>      Do you have a shebang line at the top of the script?

What do you mean executing it with bash?  I run the file with:
sh file.sh

There is more stuff in the file and if I edit out the array stuff it
runs fine with no errors.  I am wondering if I should change my shebang?
Or maybe I should start up bash differently?  Are there warning commands
like perl's -w??  Or maybe I should just write the dam thing in perl
:).  I would probably be done the script by now if I wrote it in
perl....but I would like to get better at bash.

Thanks for the help.

Later

> 
> > However, when I run this I get the error:
> > import.sh: 16: Syntax error: word unexpected (expecting ")")
> > Which is on the line with:
> > export_tables=( "cp_visa" "cp_mc" "cp_diners" "cp_amex" )
> >
> > If I run this on my Mandrake Linux box it runs find however when I run
> > it on my freeBSD server I get the error.
> > When I run bash --version on the freeBSD box I get:
> > GNU bash, version 2.05b.0(1)-release (i386-portbld-freebsd5.2)
> > Copyright (C) 2002 Free Software Foundation, Inc.
> >
> > Does this version not support arrays?  Is there some setting I have to
> > edit?
> >
> > Thanks for the help.
> >
> > Later
> >
> >
> >
-- 
Devin Whalen
Programmer
Synaptic Vision Inc
Phone-(416) 539-0801
Fax- (416) 539-8280
1179A King St. West
Toronto, Ontario
Suite 309 M6K 3C5
Home-(416) 653-3982
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list