向python传参:
在shell脚本里向一个python文件传递参数:第一个参数是字符串,第二个参数是int,第三个参数是字符串
在 Shell 脚本中,你可以通过命令行参数向 Python 脚本传递参数。下面是一个示例,演示如何在 Shell 脚本中向 Python 文件传递字符串、整数和字符串参数:
Shell 脚本(script.sh):
#!/bin/bash
# 定义参数
string_param="Hello"
int_param=42
another_string_param="World"
# 执行 Python 脚本并传递参数
python script.py "$string_param" "$int_param" "$another_string_param"
Python 脚本(script.py):
import sys
# 读取命令行参数
string_param = sys.argv[1]
int_param = int(sys.argv[2])
another_string_param = sys.argv[3]
# 现在可以在 Python 脚本中使用这些参数了
print("First parameter (string):", string_param)
print("Second parameter (integer):", int_param)
print("Third parameter (string):", another_string_param)
shell脚本向另一个shell脚本传参
在shell脚本里向另一个shell文件传递参数:第一个参数是字符串,第二个参数是int,第三个参数是字符串,第四个参数也是字符串、
#!/bin/bash
# 定义参数
string_param="Hello"
int_param=42
another_string_param="World"
fourth_param="OpenAI"
# 执行另一个 Shell 脚本并传递参数
./another_script.sh "$string_param" "$int_param" "$another_string_param" "$fourth_param"
另一个shell脚本:
#!/bin/bash
# 读取传递的参数
string_param="$1"
int_param="$2"
another_string_param="$3"
fourth_param="$4"
# 在另一个 Shell 脚本中使用这些参数
echo "First parameter (string): $string_param"
echo "Second parameter (integer): $int_param"
echo "Third parameter (string): $another_string_param"
echo "Fourth parameter (string): $fourth_param"
以下是我在工作中的一个实例:
文件目录这样:
_cpu.sh运行需要调用cpu_submit.sh需要调用.py文件
涉及到shell传参shell,shell传参python:
_cpu.sh这样:
cpu_submit.sh这样:
.py这样:
这里有一个地方我一直不知道: