Can a python script execute a function inside a bash script?

后端 未结 3 449
孤独总比滥情好
孤独总比滥情好 2020-12-31 03:38

I have a bash script provided by a 3rd party which defines a set of functions. Here\'s a template of what that looks like

$ cat test.sh

#!/bin/bash

define         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 04:10

    Yes, indirectly. Given this foo.sh:

    function go() { 
        echo "hi" 
    }
    

    Try this:

    >>> subprocess.Popen(['bash', '-c', '. foo.sh; go'])
    

    Output:

    hi
    

提交回复
热议问题