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

后端 未结 3 450
孤独总比滥情好
孤独总比滥情好 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:04

    No, the function is only available within that bash script.

    What you could do is adapt the bash script by checking for an argument and execute functions if a specific argument is given.

    For example

    # $1 is the first argument
    
    case $1 in
     "go" )
           go
           ;;
     "otherfunc" )
           otherfunc
           ;;
     * )
           echo "Unknown function"
           ;;
    esac 
    

    Then you can call the function like this:

    subprocess.call("test.sh otherfunc")
    

提交回复
热议问题