我使用bash脚本执行python脚本,它工作正常。但是我试图找到一种从python执行获取变量(用于bash使用)的方法。例如:
#!/bin/sh
python Script.py Michael 17
python Script.py Andrea 19
echo "Script was executed with : Michael, 17 "
echo "Script was executed with : Andrea 19"
有没有办法获得这些变量?我想避免分配例如。迈克尔,17岁开始抨击变量。
感谢。
答案 0 :(得分:1)
您可以定义参数并将这些参数传递给两者,如下所示;
#!/bin/sh
declare -a args1
declare -a args2
args1=("Michael" "17")
args2=("Andrea" "19")
python Script.py "${args1[@]}"
python Script.py "${args2[@]}"
echo "Script was executed with : ${args1[*]}"
echo "Script was executed with : ${args2[*]}"