如何将参数传递给 shell 脚本?

时间:2021-01-11 21:32:42

标签: python bash shell argparse

我有一个指向 Python 脚本的 shell 脚本。

脚本.sh

#!/bin/bash
python /folder/script.py

Python 脚本接受一个参数,例如 script.py -d 20210107

我尝试使用日期参数(如 script.sh -d 20210107)运行 shell 脚本,但这不起作用。我需要在我的 shell 脚本中添加一些东西来解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

#!/bin/bash
python /folder/script.py "$@"

使用 $@ 将参数从上层脚本传递到下层脚本。