Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So I found a way to transfer environment variables through ssh without having to change neither server nor client: Transferring environment variable through SSH / quoting in bash/sh/csh/tcsh

But I would also like to be able to transfer bash functions like this one:

$ myfunc() {
> echo Func $1
> }
$ export -f myfunc
$ parallel myfunc ::: a
Func a

Functions are not transferred through ssh:

$ parallel -S server myfunc ::: a
bash: myfunc: command not found
$ parallel --env myfunc -S server myfunc ::: a
bash: line 2: myfunc: command not found

But the content of the function is transferred nicely:

$ parallel --env myfunc -S server echo \$myfunc ::: a
() { echo Func $1} a

So it seems all I need to do now is to somehow tell bash that $myfunc is really the function myfunc.

How can I do that?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

That actually proved to be fairly easy (except it does not work in csh). Simply do:

eval myfunc$myfunc

It unfortunately crashes normal variables, to avoid this only do the eval for variables for which the content start with '() {'; that seems to be bash's signature for functions.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.