Cecil Westerhof <
Ce...@decebal.nl> wrote:
> When using:
> regexp -all -line "^${sensor}: +(\[^ \]+) " [exec sensors] -> temperature
>
> The last match will be put in temperature.
Which is as per the documentation (note the last sentence below):
man regexp:
-all Causes the regular expression to be matched as many
times as possible in the string, returning the total number
of matches found. If this is specified with match variables,
they will contain information for the last match only.
If you want all the matches, you have to use -inline instead of match
variables, and you get back a list, not an array:
$ rlwrap tclsh
% set r [regexp -all -line -inline {^(fan.*)$} [exec sensors] ]
{fan1: 1607 RPM (min = 0 RPM)} {fan1: 1607 RPM (min = 0 RPM)} {fan2: 0 RPM (min = 0 RPM)} {fan2: 0 RPM (min = 0 RPM)} {fan3: 0 RPM (min = 0 RPM)} {fan3: 0 RPM (min = 0 RPM)}
% join $r \n
fan1: 1607 RPM (min = 0 RPM)
fan1: 1607 RPM (min = 0 RPM)
fan2: 0 RPM (min = 0 RPM)
fan2: 0 RPM (min = 0 RPM)
fan3: 0 RPM (min = 0 RPM)
fan3: 0 RPM (min = 0 RPM)
%
Note that the list gives you both the matchVar and subMatchVar for each
match in the regexp, which is why the lines are doubled above. You can
extract the odd or even list elements with a foreach loop or lmap. And
which you extract (odd or even elements) depends on which you end up
wanting.