although I still don’t fully understand that sed line
and could never have come up with it myself:
there should be a comma after id (the third line of the “top” output)
the above is not a quote anymore as I already changed that
… and it only works reliably if I set LANG=C as well …
ps (a few hours later):
the original script does work when setting LANG=C in the calling terminal or in the script
So: it is probably not the comma / point after id in the sed line
(which I do not understand)
but something else
comma or point makes no difference - but the LANG setting does
it ensures consistency
different LANG settings produce slightly different output
some use decimal point, some comma - and the first column varies between %Cpu(s): and %CPU(s):
so that the grep command returns empty handed in one case
tricky