Combine GNU with an array?

How to issue a command in GNU in parallel with an array? For example, I have this array:

x=(0.1 0.2 0.5) 

and now I want to pass it to some command in parallel

 parallel echo ::: $x 

This does not work. It passes all arguments to one call, as it prints

 0.1 0.2 0.5 

instead

 0.1 0.2 0.5 

which is the way out

 parallel echo ::: 0.1 0.2 0.5 

How can I do it right?

+5
source share
2 answers

If you want to provide all the elements of an array, use:

 parallel echo ::: ${x[@]} 
+4
source

From: http://www.gnu.org/software/parallel/man.html

EXAMPLE: Using shell variables When using shell variables, you need to quote them correctly, because otherwise they can be divided into spaces.

Pay attention to the difference between:

 V=("My brother 12\" records are worth <\$\$\$>"'!' Foo Bar) parallel echo ::: ${V[@]} # This is probably not what you want 

and

 V=("My brother 12\" records are worth <\$\$\$>"'!' Foo Bar) parallel echo ::: "${V[@]}" 

When using variables in an actual command containing special characters (for example, space), you can quote them using "$ VAR" or using "and -q:

 V="Here are two " parallel echo "'$V'" ::: spaces parallel -q echo "$V" ::: spaces 
+2
source

Source: https://habr.com/ru/post/1245178/


All Articles