(Fwd) Re:Bash Programming

Devin Whalen devin-Gq53QDLGkWIleAitJ8REmdBPR1lH4CV8 at public.gmane.org
Thu Aug 19 14:24:03 UTC 2004


> 
> > 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"
> 
> The second line is commented out.
> 
> To make an array, another way to do it is like this:
> 
>     export_tables='table1 table2 table3 table4'
> 
> ... assuming there is no whitespace in any of the table names.
> 
> > 
> >         for table in ${export_tables[@]};
> 
> to do it my way:
> 
>           for table in $export_tables ; do
>               echo $table
>           done
> 
> there is no need of a semicolon if you have a newline between the "for" and 
> "do"
> statements.
> 
> >                 do
> >                   echo "$table"
> >                 done
> > 
> > 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
> > 
> > 

Thanks for the help everyone.  I finally sat down and learned bash
yesterday.  Now I don't have to run to perl when a small bash script
would suffice.  In fact I just wrote one just now that is going to save
me a lot of time :).


You may notice that /bin/sh and /bin/bash are in fact the same file on
your
> Linux box, but that they are NOT the same on the FreeBSD box.  sh and bash are
> not the same thing, though any legal sh script should execute just fine in bash
> (by design).  The reverse, as you've found, is not true.  ;)

Without that little piece of info I might have gone insane yesterday trying to figure out why my code wouldn't work.  
Thank god for this list!


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