您需要导出shell函数,因此它将由子shell继承.
#!/bin/sh function my_test(){ echo this is a test $1 } my_test 1 export -f my_test python -c "from subprocess import check_output; print(check_output('my_test 2', shell=True))"