解释一下shell脚本含义,并转换成python脚本 if grep -iw "FT2-MP1" /root/TestPlat/common/test_scene.ini ;then slot_temp=$(cat ${contrl_num}_bus_info.txt | awk -F / '{print $5}' | awk -F "." '{print $2}') else slot_temp=$(cat ${contrl_num}_bus_info.txt | awk -F "/" '{print $7}' | cut -b 9-10)
时间: 2024-01-22 14:20:55 浏览: 125
Shell-script-programming-guide.zip_Linux/Unix编程_Unix_Linux_
这段shell脚本的含义是:首先在/root/TestPlat/common/test_scene.ini文件中查找关键字"FT2-MP1",如果存在,则执行第一条命令,将${contrl_num}_bus_info.txt文件中第5个"/"和"."之间的字符串赋值给变量slot_temp;如果不存在,则执行第二条命令,将${contrl_num}_bus_info.txt文件中第7个"/"后两个字符(即第9到10个字符)的字符串赋值给变量slot_temp。
对应的Python脚本如下:
```python
import os
with open('/root/TestPlat/common/test_scene.ini') as f:
if 'FT2-MP1' in f.read():
with open(f'{contrl_num}_bus_info.txt') as f2:
path_parts = f2.read().split('/')
if len(path_parts) >= 5:
slot_temp = path_parts[4].split('.')[1]
else:
slot_temp = path_parts[6][8:10]
```
注意,这里的Python脚本假定了变量`contrl_num`已经被定义。
阅读全文