K
K
ksvdon2014-08-30 18:43:37
bash
ksvdon, 2014-08-30 18:43:37

I want to scatter strings into variables, what's wrong?

I read the file and put each line into a variable.

#!/bin/bash
myl=0
while read line
do
let myl=$myl+1
accum$myl="$line"
done < source.txt

It looks like it is, but it gives me an error:
parce.sh: line 7: accum1=2014-08-03 12:00:00  root             0       0.0     0.0     1       400     1000    1000: command not found
parce.sh: line 7: accum2=2014-08-03 06:00:00  root             0       0.0     0.0     1       400     1000    1000: command not found

those. we got numbered variables accum1,2,3 etc. and lines from the file .... It seems like everything I wanted. But that's why "command not found"? Where did I screw up?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2014-08-30
@ksvdon

Use arrays

#!/bin/bash
myl=0
while read line
do
let myl=$myl+1
accum[$myl]=$line
echo ${accum[myl]}
done < source.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question