|
From: sfeam <sf...@us...> - 2014-05-20 15:40:29
|
On Tuesday, 20 May 2014 06:33:44 AM atoms.h wrote:
> Hi all,
>
> i have a strange problem regarding string variables and iterations. What I'd
> like to do is to handle operations for several input files in a loop:
>
> $ list = "file1.dat file2.dat file3.dat ..."
> $ item(n) = word(list,n)
> $ do for [i = 1 : words(list)]{
> $ file = item(i)
> $ total = `echo $(awk '/Total/ {print $4}' @file)`
> $ }
You cannot change the definition of a macro inside a do loop.
The macro is expanded before the loop is executed, so the
resulting expansion will be the same every time through the
loop.
But I don't see from the fragment there why you need to use
a macro anyhow. What is wrong with using item(i) directly?
Ethan
> This always complains that 'file' is not a string (for the awk command).
> Outside the loop, however, it works:
>
> $ list = "file1.dat file2.dat file3.dat ..."
> $ item(n) = word(list,n)
> $ do for [i = 1 : words(list)]{
> $ file = item(i)
> $ }
> $ total = `echo $(awk '/Total/ {print $4}' @file)`
>
> So there seems something strange is happening in the loop which I don't
> quite understand. Like if the awk command would be executed first or
> something...
> If anyone has some inside or better idea I would very much appreciate it!
>
> Kind regards,
> Thomas
|