[K12OSN] OT: Bash help

Robert Arkiletian robark at gmail.com
Mon Nov 19 18:29:33 UTC 2007


On Nov 19, 2007 9:59 AM, Peter Hartmann <ascensiontech at gmail.com> wrote:
> I'm trying to set up a large number of arrays with a for do loop.
> It's not working, so to troubleshoot I'm simplifying it and only
> seeing if can set up an array variable with a variable.
>
> LIST=ffirst
>
> #Declare array
> declare -a ffirst
> #Open file for reading to array
> exec 10<ffirst   #  ffirst is also my filename
> let count=0
>
> while read LINE <&10; do
>
>    $LIST[$count]=$LINE
>     ((count++))
> done
> exec 10>&-

I'm not sure exactly what your trying to do but if you  just want to
open a file and read names into an array try this

#!/usr/bin/python
f = file('/path/to/ffirst','r')
mylist=[]
for x in f.readlines():
   mylist.append(x)
print mylist


note there must be a tab or 4 spaces before mylist.append(x)

-- 
Robert Arkiletian
Eric Hamber Secondary, Vancouver, Canada
Fl_TeacherTool http://www3.telus.net/public/robark/Fl_TeacherTool/
C++ GUI tutorial http://www3.telus.net/public/robark/




More information about the K12OSN mailing list