Bash Programming

Chris F.A. Johnson c.f.a.johnson-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org
Wed Aug 18 21:19:15 UTC 2004


On Wed, 18 Aug 2004, Devin Whalen wrote:

> 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

     If you do that in FreeBSD, you are not using bash; on FreeBSD, sh
     is the same as ash in Linux, and it doesn't have arrays.

     Try:

bash file.sh

     Or if bash is your shell, just:

file.sh

     Or you can put a shebang as the first line of your file (check the
     location of bash on your box):

#! /usr/local/bin/bash


-- 
 	Chris F.A. Johnson                http://cfaj.freeshell.org/shell
 	=================================================================
                 Everything in moderation -- including moderation
--
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