Executing a local shell function on a remote host over ssh using Python
问题 My .profile defines a function myps () { ps -aef|egrep "a|b"|egrep -v "c\-" } I'd like to execute it from my python script import subprocess subprocess.call("ssh user@box \"$(typeset -f); myps\"", shell=True) Getting an error back bash: -c: line 0: syntax error near unexpected token `;' bash: -c: line 0: `; myps' Escaping ; results in bash: ;: command not found 回答1: The original command was not interpreting the ; before myps properly. Using sh -c fixes that, but... ( please see Charles Duffy