如何将字符串从 bash 传递到 python 函数

1 scripting ssh python3

我有一个 python 函数,它接受一个参数作为输入,我想自动化并通过 bash 调用它。但是当我在调用它时传递变量(字符串)时,bash 给出错误

a="test"
python -c "from pipeline_runs.z_full_pipeline import test; test($a)"
Run Code Online (Sandbox Code Playgroud)

失败了

NameError: name 'test' is not defined
Run Code Online (Sandbox Code Playgroud)

但当变量为 int 时,效果相同

a="10"
python -c "from pipeline_runs.z_full_pipeline import test; test($a)"
Run Code Online (Sandbox Code Playgroud)

当第一个代码失败时它会运行。任何人都可以解释为什么会出现这样的行为,以及我应该更改什么才能将字符串从 bash 脚本传递到 python 函数

ter*_*don 5

改为将其设为 shell 函数。将其粘贴到您的终端中,或添加到 shell 的配置文件中(例如,~/.bashrc对于 bash)

pipeline_test(){
  python -c 'from sys import argv; from pipeline_runs.z_full_pipeline import test; test(argv[1])' "$@"
}
Run Code Online (Sandbox Code Playgroud)

然后运行为

pipeline_test "$a"
Run Code Online (Sandbox Code Playgroud)