This question comes from this other. I thought it was proper to make
another, rather than editing the original one.
This is my example case scenario (an array with two commands I would like to execute):
luis@Balanceador:~$ echo ${cmds[@]}
ls -la echo 'hola'
luis@Balanceador:~$ echo ${cmds[0]}
ls -la
luis@Balanceador:~$ echo ${cmds[1]}
echo 'hola'
I would like to store the results of each command in a variable using GNU Parallel, like in:
luis@Balanceador:~$ value0="$(${cmds[0]})"
luis@Balanceador:~$ printf "$value0"
total 36
drwxr-xr-x 2 luis luis 512 Jun 26 23:09 .
drwxr-xr-x 13 luis luis 512 Jun 26 22:50 ..
-rw-r--r-- 1 luis luis 1554 Jun 26 18:31 MostrarDatosRed.config
-rwxr-xr-x 1 luis luis 8335 Jun 26 23:44 MostrarDatosRed.sh
-rwxr-xr-x 1 luis luis 98 Jun 26 23:10 TestParallel.sh
-rw-r--r-- 1 luis luis 19 Jun 26 18:01 instrucciones.txt
-rw-r--r-- 1 luis luis 2 Jun 26 22:06 prueba.txt
and…
luis@Balanceador:~$ value1="$(${cmds[1]})"
luis@Balanceador:~$ printf "$value1"
'hola'
How can I do this using GNU Parallel?
Best Answer
I know of no elegant way to do this. Sopalajo comes with one way to do it. Here is another that does not use tempfiles but which deals wrongly if the output contains \377 (ascii 255):