2010-08-05 4 views
3

Je ne suis pas sûr que ce soit possible, mais je cherche un moyen d'appeler une fonction bash à partir de son sous-processus. Il pourrait être quelque chose comme:Appel des fonctions bash à partir du sous-processus

function testfunc() { echo test function; } 
bash -c 'testfunc' 

Cela ne fonctionne évidemment pas, mais est-il possible de réaliser quelque chose comme ça?

Merci beaucoup pour votre aide!

+0

double possible: http://stackoverflow.com/questions/2199455/bash-how-to-call-a-function-declared-in-a-parent-shell – Vijay

Répondre

4
$ function blargh() { 
> echo $1 
> } 
$ export -f blargh 
$ bash 
$ blargh hi there 
hi 
$ exit 
$ bash -c "blargh hi there" 
hi 

export -f est le bit non évident.

$ help export 
export: export [-fn] [name[=value] ...] or export -p 
    Set export attribute for shell variables. 

    Marks each NAME for automatic export to the environment of subsequently 
    executed commands. If VALUE is supplied, assign VALUE before exporting. 

    Options: 
     -f refer to shell functions 
    ... 
+0

Hey, merci beaucoup! – Sahas

Questions connexes