[K12OSN] OT: Bash help

Peter Hartmann ascensiontech at gmail.com
Mon Nov 19 19:39:26 UTC 2007


Hey Robert,
I always forget to paint the bigger picture....I'm making a csv file
from many textfiles.    This last part works well....so I'm hoping to
keep it.  Eventually there will be LOTS of fields, not just 2.

LIMIT=400
for ((a=0; a <= LIMIT ; a++))
do
  echo  ${ffirst[$a]}:${flast[$a]} # >> contacts.csv
done
echo; echo

Well, I have about 40-50 arrays to set up from files...and I'm lazy.
;)  Just trying to automate it. I guess I could always write a script
to write that portion of the script.

What it boils down to is this:  (this is out of context to illustrate
my confusion)

#!/bin/bash
a=name
$a=b

echo $name

What I want to get from this script is "b"  but instead I get:
./vartest: line 3: name=b: command not found

I want the shell to interpret line 3 not as a command but as setting
the variable name=b.   Get it?   If could explicitly state the command
that is implied by 'name=b' in the shell, then I think I could do what
I want.


Thanks,
Peter

P.S. Can one use  ksh, perl or python in bash in the same way that one uses awk?

On Nov 19, 2007 1:29 PM, Robert Arkiletian <robark at gmail.com> wrote:
> 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/
>
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>
>




More information about the K12OSN mailing list