Search code examples
bashparallel-processingzshgnu-parallel

export function from zsh to bash for use in gnu parallel


How do I export a function from zsh, so that I can use it in gnu parallel?

example:

function my_func(){ echo $1;}
export -f my_func
parallel "my_func {}" :::  1 2

in bash will output

1
2

whereas in zsh it will output error messages

/bin/bash: my_func: command not found
/bin/bash: my_func: command not found

Solution

  • A lot has changed since 2014.

    Today you simply do:

    # Activate env_parallel function (can be done in .zshenv)
    . `which env_parallel.zsh`
    
    function my_func(){ echo $1;}
    env_parallel "my_func {}" :::  1 2
    

    If your environment is big:

    # Activate env_parallel function (can be done in .zshenv)
    . `which env_parallel.zsh`
    
    # Record which environment to ignore
    env_parallel --session
    
    function my_func(){ echo $1;}
    env_parallel "my_func {}" :::  1 2