I'm trying to read a line from output, which looks like this (it comes from slurm, for those who are familiar with it):
cpu=00:00:00,energy=0,fs/disk=1389.75K,mem=556K,pages=0,vmem=203640K
After reading the line, there should be variables cpu, energy, a.s.o. with the respective value.
Initially I tried to source the output via piping:
line=$(tr ',/' ';_' <<< "cpu=00:00:00,energy=0,fs/disk=1389.75K,mem=556K,pages=0,vmem=203640K)"
source <<< $line
. <<< $line
But that doesn't work since source and . needs a file. So my working attempt now is:
file=$(mktemp)
{ sacct [...] | tr ',/' ';_' > $file && source $file && rm $file } || echo "Error"
My question would be: is there a better way to achieve the same result without creating a temporary file?