GNU Parallel can today successfully transfer bash environment values through ssh to the remote host:
FOO=xyz export FOO parallel --env FOO -S server 'echo $FOO' ::: bar But I would like to be able to transfer functions, too. Right now they work locally: myfunc() { echo This is a func: $1 } export -f myfunc parallel myfunc ::: bar But through ssh they do not work: $ parallel -S server myfunc ::: bar bash: myfunc: command not found $ parallel --env myfunc -S server myfunc ::: bar bash: line 2: myfunc: command not found I have managed to get the function definition copied correctly: $ parallel --env myfunc -S server echo '$myfunc' ::: bar () { echo This is a func: $1 } bar And I can even assign the definition back: $ parallel --env myfunc -S server eval myfunc'"$myfunc"'\;myfunc ::: bar This is a func: bar The problem is that from inside GNU Parallel I cannot tell whether myfunc is a function or a simple variable, and doing the eval above on simple values give the wrong results. Here are 3 tricky environment entries: d() { echo This is a func: $1 } e='() { echo This is not a func but it looks like one: $1 }' g='() { echo This is not a func and it even misses the final curly brace: $1 ' export -f d export e export g How do I from Perl see which of these are functions and which are not? I tried: perl -e 'print qx(bash -c "type -t e")' perl -e 'print qx(bash -c "type -t d")' perl -e 'print qx(bash -c "type -t g")' But they fail horribly if $g is set: $ perl -e 'print qx(bash -c "type -t e")' bash: g: line 1: syntax error: unexpected end of file bash: error importing function definition for `g' function If $g is not set they just give the wrong result: $ perl -e 'print qx(bash -c "type -t d")' function # Correct $ perl -e 'print qx(bash -c "type -t e")' function # Wrong Ideas? /Ole