Released as 20210622 ('Protasevich')
[parallel.git] / src / parset.pod
blob8df65d2beb600c06dcaa388aedeb4d4784588585
1 #!/usr/bin/perl -w
3 # SPDX-FileCopyrightText: 2021 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
4 # SPDX-License-Identifier: GFDL-1.3-or-later
5 # SPDX-License-Identifier: CC-BY-SA-4.0
7 =encoding utf8
9 =head1 NAME
11 parset - set shell variables in parallel
14 =head1 SYNOPSIS
16 B<parset> I<variablename> [options for GNU Parallel]
18 B<env_parset> I<variablename> [options for GNU Parallel]
20 =head1 DESCRIPTION
22 B<parset> is a shell function that puts the output from GNU
23 B<parallel> into shell variables.
25 B<env_parset> is a shell function that puts the output from
26 B<env_parallel> into shell variables.
28 The B<parset> and B<env_parset> functions are defined as part of
29 B<env_parallel>.
31 If I<variablename> is a single variable name, this will be treated as
32 the destination variable and made into an array.
34 If I<variablename> contains multiple names separated by ',' or space,
35 the names will be the destination variables. The number of names must
36 be at least the number of jobs - otherwise some tmp files will not be
37 cleaned up.
40 =head1 OPTIONS
42 Same as GNU B<parallel>, but they are put I<after> the destination
43 variable.
46 =head1 SUPPORTED SHELLS
48 =head2 Bash/Zsh/Ksh/Mksh
50 =head3 Examples
52 Put output into B<myarray>:
54 parset myarray seq 3 ::: 4 5 6
55 echo "${myarray[1]}"
57 Put output into vars B<$seq, $pwd, $ls>:
59 parset "seq pwd ls" ::: "seq 10" pwd ls
60 echo "$ls"
62 Put output into vars B<$seq, $pwd, $ls>:
64 into_vars=(seq pwd ls)
65 parset "${into_vars[*]}" ::: "seq 10" pwd ls
66 echo "$ls"
68 The commands to run can be an array:
70 cmd=("echo first" "echo '<<joe \"double space\" cartoon>>'" "pwd")
71 parset data ::: "${cmd[@]}"
72 echo "${data[1]}"
73 echo "${data[2]}"
75 B<parset> can read from stdin (standard input) if it is a file:
77 parset res echo < parallel_input_file
79 but B<parset> can not be part of a pipe. In particular this means it
80 cannot read from a pipe or write to a pipe:
82 seq 10 | parset res echo Does not work
84 but must instead use a tempfile:
86 seq 10 > parallel_input
87 parset res echo :::: parallel_input
88 echo "${res[1]}"
89 echo "${res[9]}"
91 or a FIFO:
93 mkfifo input_fifo
94 seq 30 > input_fifo &
95 parset res echo :::: input_fifo
96 echo "${res[1]}"
97 echo "${res[29]}"
99 or Bash/Zsh/Ksh process substitution:
101 parset res echo :::: <(seq 100)
102 echo "${res[1]}"
103 echo "${res[99]}"
105 Put output into an associative array (Bash only):
107 input=("value A" "value B")
108 parset res echo This is ::: "${input[@]}"
110 # Zip the input and res arrays to a single associative array
111 declare -A myassoc
112 for ((i=0; $i<${#input[@]}; i++)); do
113 myassoc[${input[i]}]=${res[i]}
114 done
115 echo "${myassoc["value A"]}"
117 =head3 Installation
119 Put this in the relevant B<$HOME/.bashrc> or B<$HOME/.zshenv> or B<$HOME/.kshrc>:
121 . `which env_parallel.bash`
122 . `which env_parallel.zsh`
123 source `which env_parallel.ksh`
125 E.g. by doing:
127 echo '. `which env_parallel.bash`' >> $HOME/.bashrc
128 echo '. `which env_parallel.zsh`' >> $HOME/.zshenv
129 echo 'source `which env_parallel.ksh`' >> $HOME/.kshrc
131 or by doing:
133 env_parallel --install
136 =head2 ash/dash (FreeBSD's /bin/sh)
138 =head3 Examples
140 ash does not support arrays.
142 Put output into vars B<$seq, $pwd, $ls>:
144 parset "seq pwd ls" ::: "seq 10" pwd ls
145 echo "$ls"
147 B<parset> can read from stdin (standard input) if it is a file:
149 parset res1,res2,res3 echo < parallel_input_file
151 but B<parset> can not be part of a pipe. In particular this means it
152 cannot read from a pipe or write to a pipe:
154 seq 3 | parset res1,res2,res3 echo Does not work
156 but must instead use a tempfile:
158 seq 3 > parallel_input
159 parset res1,res2,res3 echo :::: parallel_input
160 echo "$res1"
161 echo "$res2"
162 echo "$res3"
164 or a FIFO:
166 mkfifo input_fifo
167 seq 3 > input_fifo &
168 parset res1,res2,res3 echo :::: input_fifo
169 echo "$res1"
170 echo "$res2"
171 echo "$res3"
173 =head3 Installation
175 Put the relevant one of these into B<$HOME/.profile>:
177 . `which env_parallel.sh`
178 . `which env_parallel.ash`
179 . `which env_parallel.dash`
181 E.g. by doing:
183 echo '. `which env_parallel.ash`' >> $HOME/.bashrc
185 or by doing:
187 env_parallel --install
190 =head1 EXIT STATUS
192 Same as GNU B<parallel>.
195 =head1 AUTHOR
197 When using GNU B<parallel> for a publication please cite:
199 O. Tange (2011): GNU Parallel - The Command-Line Power Tool, ;login:
200 The USENIX Magazine, February 2011:42-47.
202 This helps funding further development; and it won't cost you a cent.
203 If you pay 10000 EUR you should feel free to use GNU Parallel without citing.
205 Copyright (C) 2007-10-18 Ole Tange, http://ole.tange.dk
207 Copyright (C) 2008-2010 Ole Tange, http://ole.tange.dk
209 Copyright (C) 2010-2021 Ole Tange, http://ole.tange.dk and Free
210 Software Foundation, Inc.
213 =head1 LICENSE
215 This program is free software; you can redistribute it and/or modify
216 it under the terms of the GNU General Public License as published by
217 the Free Software Foundation; either version 3 of the License, or
218 at your option any later version.
220 This program is distributed in the hope that it will be useful,
221 but WITHOUT ANY WARRANTY; without even the implied warranty of
222 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
223 GNU General Public License for more details.
225 You should have received a copy of the GNU General Public License
226 along with this program. If not, see <http://www.gnu.org/licenses/>.
228 =head2 Documentation license I
230 Permission is granted to copy, distribute and/or modify this
231 documentation under the terms of the GNU Free Documentation License,
232 Version 1.3 or any later version published by the Free Software
233 Foundation; with no Invariant Sections, with no Front-Cover Texts, and
234 with no Back-Cover Texts. A copy of the license is included in the
235 file LICENSES/GFDL-1.3-or-later.txt.
237 =head2 Documentation license II
239 You are free:
241 =over 9
243 =item B<to Share>
245 to copy, distribute and transmit the work
247 =item B<to Remix>
249 to adapt the work
251 =back
253 Under the following conditions:
255 =over 9
257 =item B<Attribution>
259 You must attribute the work in the manner specified by the author or
260 licensor (but not in any way that suggests that they endorse you or
261 your use of the work).
263 =item B<Share Alike>
265 If you alter, transform, or build upon this work, you may distribute
266 the resulting work only under the same, similar or a compatible
267 license.
269 =back
271 With the understanding that:
273 =over 9
275 =item B<Waiver>
277 Any of the above conditions can be waived if you get permission from
278 the copyright holder.
280 =item B<Public Domain>
282 Where the work or any of its elements is in the public domain under
283 applicable law, that status is in no way affected by the license.
285 =item B<Other Rights>
287 In no way are any of the following rights affected by the license:
289 =over 2
291 =item *
293 Your fair dealing or fair use rights, or other applicable
294 copyright exceptions and limitations;
296 =item *
298 The author's moral rights;
300 =item *
302 Rights other persons may have either in the work itself or in
303 how the work is used, such as publicity or privacy rights.
305 =back
307 =back
309 =over 9
311 =item B<Notice>
313 For any reuse or distribution, you must make clear to others the
314 license terms of this work.
316 =back
318 A copy of the full license is included in the file as
319 LICENCES/CC-BY-SA-4.0.txt
321 =head1 DEPENDENCIES
323 B<parset> uses GNU B<parallel>.
326 =head1 SEE ALSO
328 B<parallel>(1), B<env_parallel>(1), B<bash>(1).
331 =cut