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
11 env_parallel - export environment to GNU parallel
16 B<env_parallel> [--record-env|--session|--end-session]
17 [options for GNU Parallel]
22 B<env_parallel> is a shell function that exports the current
23 environment to GNU B<parallel>.
25 If the shell function is not loaded, a dummy script will be run
26 instead that explains how to install the function.
28 B<env_parallel> is 100 ms slower at startup than pure GNU
29 B<parallel>, and takes up to 30% longer to start a job (typically 15 ms).
31 Due to the problem with environment space (see below) the recommended
34 # Do --record-env into $PARALLEL_IGNORED_NAMES
35 env_parallel --session
37 # Define whatever you want to use
38 myfunc() { myalias and functions $myvar work. $1.; }
39 alias myalias='echo Aliases'
42 # env_parallel will not export names in $PARALLEL_IGNORED_NAMES
43 env_parallel -S localhost myfunc ::: Hooray
47 # Record the "clean" environment (this only needs to be run once)
48 env_parallel --record-env
50 # Optionally edit ~/.parallel/ignored_vars (only needed once)
52 # Define whatever you want to use
53 myfunc() { myalias and functions $myvar work. $1.; }
54 alias myalias='echo Aliases'
57 # Use --env _ to only transfer the names not in the "empty" environment
58 env_parallel --env _ -S localhost myfunc ::: Hooray
60 In B<csh> B<--session> is not supported:
62 # Record the "clean" environment - this only needs to be run once
63 env_parallel --record-env
65 # Optionally edit ~/.parallel/ignored_vars - only needed once
67 # Define whatever you want to use
68 alias myalias 'echo Aliases $myvar \!*.'
69 set myvar='and variables'
71 # Use --env _ to only transfer the names not in the "empty" environment
72 env_parallel --env _ -S localhost myalias ::: work
74 =head2 Environment space
76 By default B<env_parallel> will export all environment variables,
77 arrays, aliases, functions and shell options (see details for the
78 individual shells below).
80 But this only works if the size of the current environment is smaller
81 than the maximal length of a command and smaller than half of the max
82 if running remotely. E.g. The max size of Bash's command is 128 KB, so
83 B<env_parallel> will fail if 'B<set | wc -c>' is bigger than 128
84 KB. Technically the limit is in execve(1) which IPC::open3 uses.
86 Bash completion functions are well-known for taking up well over 128
87 KB of environment space and the primary reason for causing
88 B<env_parallel> to fail.
90 Instead you can use B<--env> to specify which variables, arrays,
91 aliases and functions to export as this will only export those with
92 the given name. Or follow the recommended usage in shown in
98 Same as GNU B<parallel> in addition to these:
102 =item B<--end-session>
104 Undo last B<--session>
107 =item B<--record-env>
109 Record all names currently defined to be ignored every time running
110 B<env_parallel> in the future.
115 Ignore all names currently defined. Aliases, variables, arrays, and
116 functions currently defined will not be transferred.
118 But names defined I<after> running B<parallel --session> I<will> be
121 This is only valid in the running shell, and can be undone with
122 B<parallel --end-session>.
124 You can run multiple B<--session> inside each other:
126 env_parallel --session
129 env_parallel -Slocalhost 'echo var is $var' ::: ignored
130 env_parallel --session
131 # var is not transferred
132 env_parallel -Slocalhost 'echo var is $var' ::: ignored
133 env_parallel --end-session
134 # var is transferred again
135 env_parallel -Slocalhost 'echo var is $var' ::: ignored
142 =head1 SUPPORTED SHELLS
148 Put this in $HOME/.profile:
150 . `which env_parallel.ash`
154 echo '. `which env_parallel.ash`' >> $HOME/.profile
158 B<--env> is supported to export only the variable, or alias with the
159 given name. Multiple B<--env>s can be given.
161 B<--session> is supported.
167 alias myecho='echo aliases'
168 env_parallel myecho ::: work
169 env_parallel -S server myecho ::: work
170 env_parallel --env myecho myecho ::: work
171 env_parallel --env myecho -S server myecho ::: work
173 alias multiline='echo multiline
175 env_parallel multiline ::: work
176 env_parallel -S server multiline ::: work
177 env_parallel --env multiline multiline ::: work
178 env_parallel --env multiline -S server multiline ::: work
182 ash cannot list defined functions - thus is not supported.
187 env_parallel echo '$myvar' ::: work
188 env_parallel -S server echo '$myvar' ::: work
189 env_parallel --env myvar echo '$myvar' ::: work
190 env_parallel --env myvar -S server echo '$myvar' ::: work
194 Arrays are not supported by Ash.
202 Put this in $HOME/.bashrc:
204 . `which env_parallel.bash`
208 echo '. `which env_parallel.bash`' >> $HOME/.bashrc
212 B<--env> is supported to export only the variable, alias, function, or
213 array with the given name. Multiple B<--env>s can be given.
215 B<--session> is supported.
221 alias myecho='echo aliases'
222 env_parallel myecho ::: work
223 env_parallel -S server myecho ::: work
224 env_parallel --env myecho myecho ::: work
225 env_parallel --env myecho -S server myecho ::: work
227 alias multiline='echo multiline
229 env_parallel 'multiline {};
230 echo but only when followed by a newline' ::: work
231 env_parallel -S server 'multiline {};
232 echo but only when followed by a newline' ::: work
233 env_parallel --env multiline 'multiline {};
234 echo but only when followed by a newline' ::: work
235 env_parallel --env multiline -S server 'multiline {};
236 echo but only when followed by a newline' ::: work
240 myfunc() { echo functions $*; }
241 env_parallel myfunc ::: work
242 env_parallel -S server myfunc ::: work
243 env_parallel --env myfunc myfunc ::: work
244 env_parallel --env myfunc -S server myfunc ::: work
249 env_parallel echo '$myvar' ::: work
250 env_parallel -S server echo '$myvar' ::: work
251 env_parallel --env myvar echo '$myvar' ::: work
252 env_parallel --env myvar -S server echo '$myvar' ::: work
256 myarray=(arrays work, too)
257 env_parallel -k echo '${myarray[{}]}' ::: 0 1 2
258 env_parallel -k -S server echo '${myarray[{}]}' ::: 0 1 2
259 env_parallel -k --env myarray echo '${myarray[{}]}' ::: 0 1 2
260 env_parallel -k --env myarray -S server \
261 echo '${myarray[{}]}' ::: 0 1 2
267 Due to a bug in Bash, aliases containing newlines must be followed by
268 a newline in the command. Some systems are not affected by this bug,
269 but will print a warning anyway.
273 B<env_parallel> for B<csh> breaks B<$PARALLEL>, so do not use
278 Put this in $HOME/.cshrc:
280 source `which env_parallel.csh`
284 echo 'source `which env_parallel.csh`' >> $HOME/.cshrc
288 B<--env> is supported to export only the variable, alias, or
289 array with the given name. Multiple B<--env>s can be given.
295 alias myecho 'echo aliases'
296 env_parallel myecho ::: work
297 env_parallel -S server myecho ::: work
298 env_parallel --env myecho myecho ::: work
299 env_parallel --env myecho -S server myecho ::: work
303 Not supported by B<csh>.
308 env_parallel echo '$myvar' ::: work
309 env_parallel -S server echo '$myvar' ::: work
310 env_parallel --env myvar echo '$myvar' ::: work
311 env_parallel --env myvar -S server echo '$myvar' ::: work
313 =item arrays with no special chars
315 set myarray=(arrays work, too)
316 env_parallel -k echo \$'{myarray[{}]}' ::: 1 2 3
317 env_parallel -k -S server echo \$'{myarray[{}]}' ::: 1 2 3
318 env_parallel -k --env myarray echo \$'{myarray[{}]}' ::: 1 2 3
319 env_parallel -k --env myarray -S server \
320 echo \$'{myarray[{}]}' ::: 1 2 3
329 Put this in $HOME/.profile:
331 . `which env_parallel.dash`
335 echo '. `which env_parallel.dash`' >> $HOME/.profile
339 B<--env> is supported to export only the variable, or alias with the
340 given name. Multiple B<--env>s can be given.
342 B<--session> is supported.
348 alias myecho='echo aliases'
349 env_parallel myecho ::: work
350 env_parallel -S server myecho ::: work
351 env_parallel --env myecho myecho ::: work
352 env_parallel --env myecho -S server myecho ::: work
354 alias multiline='echo multiline
356 env_parallel multiline ::: work
357 env_parallel -S server multiline ::: work
358 env_parallel --env multiline multiline ::: work
359 env_parallel --env multiline -S server multiline ::: work
363 dash cannot list defined functions - thus is not supported.
368 env_parallel echo '$myvar' ::: work
369 env_parallel -S server echo '$myvar' ::: work
370 env_parallel --env myvar echo '$myvar' ::: work
371 env_parallel --env myvar -S server echo '$myvar' ::: work
375 dash does not support arrays.
384 Put this in $HOME/.config/fish/config.fish:
386 source (which env_parallel.fish)
390 echo 'source (which env_parallel.fish)' \
391 >> $HOME/.config/fish/config.fish
395 B<--env> is supported to export only the variable, alias, function, or
396 array with the given name. Multiple B<--env>s can be given.
398 B<--session> is supported.
404 alias myecho 'echo aliases'
405 env_parallel myecho ::: work
406 env_parallel -S server myecho ::: work
407 env_parallel --env myecho myecho ::: work
408 env_parallel --env myecho -S server myecho ::: work
415 env_parallel myfunc ::: work
416 env_parallel -S server myfunc ::: work
417 env_parallel --env myfunc myfunc ::: work
418 env_parallel --env myfunc -S server myfunc ::: work
423 env_parallel echo '$myvar' ::: work
424 env_parallel -S server echo '$myvar' ::: work
425 env_parallel --env myvar echo '$myvar' ::: work
426 env_parallel --env myvar -S server echo '$myvar' ::: work
430 set myarray arrays work, too
431 env_parallel -k echo '$myarray[{}]' ::: 1 2 3
432 env_parallel -k -S server echo '$myarray[{}]' ::: 1 2 3
433 env_parallel -k --env myarray echo '$myarray[{}]' ::: 1 2 3
434 env_parallel -k --env myarray -S server \
435 echo '$myarray[{}]' ::: 1 2 3
444 Put this in $HOME/.kshrc:
446 source `which env_parallel.ksh`
450 echo 'source `which env_parallel.ksh`' >> $HOME/.kshrc
454 B<--env> is supported to export only the variable, alias, function, or
455 array with the given name. Multiple B<--env>s can be given.
457 B<--session> is supported.
463 alias myecho='echo aliases'
464 env_parallel myecho ::: work
465 env_parallel -S server myecho ::: work
466 env_parallel --env myecho myecho ::: work
467 env_parallel --env myecho -S server myecho ::: work
469 alias multiline='echo multiline
471 env_parallel multiline ::: work
472 env_parallel -S server multiline ::: work
473 env_parallel --env multiline multiline ::: work
474 env_parallel --env multiline -S server multiline ::: work
478 myfunc() { echo functions $*; }
479 env_parallel myfunc ::: work
480 env_parallel -S server myfunc ::: work
481 env_parallel --env myfunc myfunc ::: work
482 env_parallel --env myfunc -S server myfunc ::: work
487 env_parallel echo '$myvar' ::: work
488 env_parallel -S server echo '$myvar' ::: work
489 env_parallel --env myvar echo '$myvar' ::: work
490 env_parallel --env myvar -S server echo '$myvar' ::: work
494 myarray=(arrays work, too)
495 env_parallel -k echo '${myarray[{}]}' ::: 0 1 2
496 env_parallel -k -S server echo '${myarray[{}]}' ::: 0 1 2
497 env_parallel -k --env myarray echo '${myarray[{}]}' ::: 0 1 2
498 env_parallel -k --env myarray -S server \
499 echo '${myarray[{}]}' ::: 0 1 2
508 Put this in $HOME/.mkshrc:
510 source `which env_parallel.mksh`
514 echo 'source `which env_parallel.mksh`' >> $HOME/.mkshrc
518 B<--env> is supported to export only the variable, alias, function, or
519 array with the given name. Multiple B<--env>s can be given.
521 B<--session> is supported.
527 alias myecho='echo aliases'
528 env_parallel myecho ::: work
529 env_parallel -S server myecho ::: work
530 env_parallel --env myecho myecho ::: work
531 env_parallel --env myecho -S server myecho ::: work
533 alias multiline='echo multiline
535 env_parallel multiline ::: work
536 env_parallel -S server multiline ::: work
537 env_parallel --env multiline multiline ::: work
538 env_parallel --env multiline -S server multiline ::: work
542 myfunc() { echo functions $*; }
543 env_parallel myfunc ::: work
544 env_parallel -S server myfunc ::: work
545 env_parallel --env myfunc myfunc ::: work
546 env_parallel --env myfunc -S server myfunc ::: work
551 env_parallel echo '$myvar' ::: work
552 env_parallel -S server echo '$myvar' ::: work
553 env_parallel --env myvar echo '$myvar' ::: work
554 env_parallel --env myvar -S server echo '$myvar' ::: work
558 myarray=(arrays work, too)
559 env_parallel -k echo '${myarray[{}]}' ::: 0 1 2
560 env_parallel -k -S server echo '${myarray[{}]}' ::: 0 1 2
561 env_parallel -k --env myarray echo '${myarray[{}]}' ::: 0 1 2
562 env_parallel -k --env myarray -S server \
563 echo '${myarray[{}]}' ::: 0 1 2
572 Put this in $HOME/.profile:
574 source `which env_parallel.pdksh`
578 echo 'source `which env_parallel.pdksh`' >> $HOME/.profile
582 B<--env> is supported to export only the variable, alias, function, or
583 array with the given name. Multiple B<--env>s can be given.
585 B<--session> is supported.
591 alias myecho="echo aliases";
592 env_parallel myecho ::: work;
593 env_parallel -S server myecho ::: work;
594 env_parallel --env myecho myecho ::: work;
595 env_parallel --env myecho -S server myecho ::: work
599 myfunc() { echo functions $*; };
600 env_parallel myfunc ::: work;
601 env_parallel -S server myfunc ::: work;
602 env_parallel --env myfunc myfunc ::: work;
603 env_parallel --env myfunc -S server myfunc ::: work
608 env_parallel echo "\$myvar" ::: work;
609 env_parallel -S server echo "\$myvar" ::: work;
610 env_parallel --env myvar echo "\$myvar" ::: work;
611 env_parallel --env myvar -S server echo "\$myvar" ::: work
615 myarray=(arrays work, too);
616 env_parallel -k echo "\${myarray[{}]}" ::: 0 1 2;
617 env_parallel -k -S server echo "\${myarray[{}]}" ::: 0 1 2;
618 env_parallel -k --env myarray echo "\${myarray[{}]}" ::: 0 1 2;
619 env_parallel -k --env myarray -S server \
620 echo "\${myarray[{}]}" ::: 0 1 2
629 Put this in $HOME/.profile:
631 . `which env_parallel.sh`
635 echo '. `which env_parallel.sh`' >> $HOME/.profile
639 B<--env> is supported to export only the variable, or alias with the
640 given name. Multiple B<--env>s can be given.
642 B<--session> is supported.
648 sh does not support aliases.
652 myfunc() { echo functions $*; }
653 env_parallel myfunc ::: work
654 env_parallel -S server myfunc ::: work
655 env_parallel --env myfunc myfunc ::: work
656 env_parallel --env myfunc -S server myfunc ::: work
661 env_parallel echo '$myvar' ::: work
662 env_parallel -S server echo '$myvar' ::: work
663 env_parallel --env myvar echo '$myvar' ::: work
664 env_parallel --env myvar -S server echo '$myvar' ::: work
668 sh does not support arrays.
675 B<env_parallel> for B<tcsh> breaks B<$PARALLEL>, so do not use
680 Put this in $HOME/.tcshrc:
682 source `which env_parallel.tcsh`
686 echo 'source `which env_parallel.tcsh`' >> $HOME/.tcshrc
690 B<--env> is supported to export only the variable, alias, or
691 array with the given name. Multiple B<--env>s can be given.
697 alias myecho 'echo aliases'
698 env_parallel myecho ::: work
699 env_parallel -S server myecho ::: work
700 env_parallel --env myecho myecho ::: work
701 env_parallel --env myecho -S server myecho ::: work
705 Not supported by B<tcsh>.
710 env_parallel echo '$myvar' ::: work
711 env_parallel -S server echo '$myvar' ::: work
712 env_parallel --env myvar echo '$myvar' ::: work
713 env_parallel --env myvar -S server echo '$myvar' ::: work
715 =item arrays with no special chars
717 set myarray=(arrays work, too)
718 env_parallel -k echo \$'{myarray[{}]}' ::: 1 2 3
719 env_parallel -k -S server echo \$'{myarray[{}]}' ::: 1 2 3
720 env_parallel -k --env myarray echo \$'{myarray[{}]}' ::: 1 2 3
721 env_parallel -k --env myarray -S server \
722 echo \$'{myarray[{}]}' ::: 1 2 3
731 Put this in $HOME/.zshrc:
733 . `which env_parallel.zsh`
737 echo '. `which env_parallel.zsh`' >> $HOME/.zshenv
741 B<--env> is supported to export only the variable, alias, function, or
742 array with the given name. Multiple B<--env>s can be given.
744 B<--session> is supported.
750 alias myecho='echo aliases'
751 env_parallel myecho ::: work
752 env_parallel -S server myecho ::: work
753 env_parallel --env myecho myecho ::: work
754 env_parallel --env myecho -S server myecho ::: work
756 alias multiline='echo multiline
758 env_parallel multiline ::: work
759 env_parallel -S server multiline ::: work
760 env_parallel --env multiline multiline ::: work
761 env_parallel --env multiline -S server multiline ::: work
765 myfunc() { echo functions $*; }
766 env_parallel myfunc ::: work
767 env_parallel -S server myfunc ::: work
768 env_parallel --env myfunc myfunc ::: work
769 env_parallel --env myfunc -S server myfunc ::: work
774 env_parallel echo '$myvar' ::: work
775 env_parallel -S server echo '$myvar' ::: work
776 env_parallel --env myvar echo '$myvar' ::: work
777 env_parallel --env myvar -S server echo '$myvar' ::: work
781 myarray=(arrays work, too)
782 env_parallel -k echo '${myarray[{}]}' ::: 1 2 3
783 env_parallel -k -S server echo '${myarray[{}]}' ::: 1 2 3
784 env_parallel -k --env myarray echo '${myarray[{}]}' ::: 1 2 3
785 env_parallel -k --env myarray -S server \
786 echo '${myarray[{}]}' ::: 1 2 3
793 Same as GNU B<parallel>.
798 When using GNU B<env_parallel> for a publication please cite:
800 O. Tange (2018): GNU Parallel 2018, March 2018, ISBN 9781387509881,
801 DOI: 10.5281/zenodo.1146014.
803 This helps funding further development; and it won't cost you a cent.
804 If you pay 10000 EUR you should feel free to use GNU Parallel without citing.
806 Copyright (C) 2007-10-18 Ole Tange, http://ole.tange.dk
808 Copyright (C) 2008-2010 Ole Tange, http://ole.tange.dk
810 Copyright (C) 2010-2021 Ole Tange, http://ole.tange.dk and Free
811 Software Foundation, Inc.
816 This program is free software; you can redistribute it and/or modify
817 it under the terms of the GNU General Public License as published by
818 the Free Software Foundation; either version 3 of the License, or
819 at your option any later version.
821 This program is distributed in the hope that it will be useful,
822 but WITHOUT ANY WARRANTY; without even the implied warranty of
823 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
824 GNU General Public License for more details.
826 You should have received a copy of the GNU General Public License
827 along with this program. If not, see <http://www.gnu.org/licenses/>.
829 =head2 Documentation license I
831 Permission is granted to copy, distribute and/or modify this
832 documentation under the terms of the GNU Free Documentation License,
833 Version 1.3 or any later version published by the Free Software
834 Foundation; with no Invariant Sections, with no Front-Cover Texts, and
835 with no Back-Cover Texts. A copy of the license is included in the
836 file LICENSES/GFDL-1.3-or-later.txt.
839 =head2 Documentation license II
847 to copy, distribute and transmit the work
855 Under the following conditions:
861 You must attribute the work in the manner specified by the author or
862 licensor (but not in any way that suggests that they endorse you or
863 your use of the work).
867 If you alter, transform, or build upon this work, you may distribute
868 the resulting work only under the same, similar or a compatible
873 With the understanding that:
879 Any of the above conditions can be waived if you get permission from
880 the copyright holder.
882 =item B<Public Domain>
884 Where the work or any of its elements is in the public domain under
885 applicable law, that status is in no way affected by the license.
887 =item B<Other Rights>
889 In no way are any of the following rights affected by the license:
895 Your fair dealing or fair use rights, or other applicable
896 copyright exceptions and limitations;
900 The author's moral rights;
904 Rights other persons may have either in the work itself or in
905 how the work is used, such as publicity or privacy rights.
915 For any reuse or distribution, you must make clear to others the
916 license terms of this work.
920 A copy of the full license is included in the file as
921 LICENCES/CC-BY-SA-4.0.txt
926 B<env_parallel> uses GNU B<parallel>.
931 B<parallel>(1), B<ash>(1), B<bash>(1), B<csh>(1), B<dash>(1),
932 B<fish>(1), B<ksh>(1), B<pdksh>(1) B<tcsh>(1), B<zsh>(1).