parset1
Set shell variables in parallel
Usage
parset variablename
[options
for
GNU
Parallel]
env_parset variablename
[options
for
GNU
Parallel]
Overview
parset is a shell function that puts the output from GNU parallel into shell variables.
env_parset is a shell function that puts the output from env_parallel into shell variables.
The parset and env_parset functions are defined as part of env_parallel.
If variablename is a single variable name, this will be treated as the destination variable. If the variable is defined as an associative array (using typeset -A myassoc), this will be used. Otherwise the variable will be made into a normal array.
If variablename contains multiple names separated by ',' or space, the names will be the destination variables. The number of names must be at least the number of jobs.
Options
Same as GNU parallel, but they are put after the destination variable.
Supported shells
Bash/Zsh/Ksh/Mksh
Examples
Put output into myarray:
parset myarray seq 3 ::: 4 5 6echo "${myarray[1]}"
Put output into vars $seq, $pwd, $ls:
parset "seq pwd ls" ::: "seq 10" pwd lsecho "$ls"
Put output into vars $seq, $pwd, $ls:
into_vars=(seq pwd ls)parset "${into_vars[*]}" ::: "seq 10" pwd lsecho "$ls"
Put output into associative array myassoc (not supported for mksh):
typeset -A myassocparset myassoc seq ::: 4 5 ::: 6 7echo "${myassoc[4 7]}"
The commands to run can be an array:
cmd=("echo first" "echo '<<joe \"double space\" cartoon>>'" "pwd")parset data ::: "${cmd[@]}"echo "${data[1]}"echo "${data[2]}"
parset can read from stdin (standard input) if it is a file:
parset res echo < parallel_input_file
but parset can not be part of a pipe. In particular this means it cannot read from a pipe or write to a pipe:
seq 10 | parset res echo Does not work
but must instead use a tempfile:
seq 10 > parallel_inputparset res echo :::: parallel_inputecho "${res[1]}"echo "${res[9]}"
or a FIFO:
mkfifo input_fifoseq 30 > input_fifo &parset res echo :::: input_fifoecho "${res[1]}"echo "${res[29]}"
or Bash/Zsh/Ksh process substitution:
parset res echo :::: <(seq 100)echo "${res[1]}"echo "${res[99]}"
Installation
Put this in the relevant $HOME/.bashrc or $HOME/.zshenv or $HOME/.kshrc:
. env_parallel.bash. env_parallel.zshsource `which env_parallel.ksh`
E.g. by doing:
echo '. env_parallel.bash' >> $HOME/.bashrcecho '. env_parallel.zsh' >> $HOME/.zshenvecho 'source `which env_parallel.ksh`' >> $HOME/.kshrc
or by doing:
env_parallel --install
ash/dash (FreeBSD's /bin/sh)
Examples
ash does not support arrays.
Put output into vars $seq, $pwd, $ls:
parset "seq pwd ls" ::: "seq 10" pwd lsecho "$ls"
parset can read from stdin (standard input) if it is a file:
parset res1,res2,res3 echo < parallel_input_file
but parset can not be part of a pipe. In particular this means it cannot read from a pipe or write to a pipe:
seq 3 | parset res1,res2,res3 echo Does not work
but must instead use a tempfile:
seq 3 > parallel_inputparset res1,res2,res3 echo :::: parallel_inputecho "$res1"echo "$res2"echo "$res3"
or a FIFO:
mkfifo input_fifoseq 3 > input_fifo &parset res1,res2,res3 echo :::: input_fifoecho "$res1"echo "$res2"echo "$res3"
Installation
Put the relevant one of these into $HOME/.profile:
. env_parallel.sh. env_parallel.ash. env_parallel.dash
E.g. by doing:
echo '. env_parallel.ash' >> $HOME/.bashrc
or by doing:
env_parallel --install
Exit status
Same as GNU parallel.
Dependencies
parset uses GNU parallel.
Releases
3 releases since Debian 12 (Bookworm); the text changed 2 times.