将Bash安装脚本转换为Python

将Bash安装脚本转换为Python,python,for-loop,Python,For Loop,我有下面的bash脚本,希望将其转换为Python,并最终添加错误处理 我试图像在bash中一样编写数组并读取它们,但在Python中找不到一种简单的方法。有什么想法吗 #!/bin/bash repos=("BloodHoundAD/BloodHound.git" "GhostPack/Seatbelt.git" "GhostPack/SharpUp.git" "yeyintminthuhtut/Awesome-Red-Teaming.git" "byt3bl33d3r/DeathStar.g

我有下面的bash脚本,希望将其转换为Python,并最终添加错误处理

我试图像在bash中一样编写数组并读取它们,但在Python中找不到一种简单的方法。有什么想法吗

#!/bin/bash
repos=("BloodHoundAD/BloodHound.git" "GhostPack/Seatbelt.git" "GhostPack/SharpUp.git" "yeyintminthuhtut/Awesome-Red-Teaming.git"
"byt3bl33d3r/DeathStar.git" "byt3bl33d3r/CrackMapExec.git" "Cn33liz/p0wnedShell.git" "EmpireProject/Empire.git"
"danielmiessler/SecLists.git" "laramies/theHarvester.git")
for i in "${repos[@]}"; do
  git clone http://github.com/$i
done
echo "There are ${#repos[@]} repos here"
感谢以下用户的大力帮助:

下面是我用Python更新的代码。希望它能帮助别人

import os
import subprocess

repos=["BloodHoundAD/BloodHound.git", "GhostPack/Seatbelt.git", "GhostPack/SharpUp.git", "yeyintminthuhtut/Awesome-Red-Teaming.git",
"byt3bl33d3r/DeathStar.git", "byt3bl33d3r/CrackMapExec.git", "Cn33liz/p0wnedShell.git", "EmpireProject/Empire.git",
"danielmiessler/SecLists.git", "laramies/theHarvester.git"]

for repo in repos:
    subprocess.Popen("git clone https://github.com/{}".format(repo) , shell=True).wait()

print ("There are {} repos in the array.".format(str(len(repos))))

首先,我们将
repos
转换为python列表。因此:

repos=["BloodHoundAD/BloodHound.git", "GhostPack/Seatbelt.git", "GhostPack/SharpUp.git", "yeyintminthuhtut/Awesome-Red-Teaming.git",
"byt3bl33d3r/DeathStar.git", "byt3bl33d3r/CrackMapExec.git", "Cn33liz/p0wnedShell.git", "EmpireProject/Empire.git",
"danielmiessler/SecLists.git", "laramies/theHarvester.git"]
然后,我们在python中创建一个for循环。在这个for循环中,我们运行
gitclone包
。我们可以通过
os.system()
运行它,而不用使用库

因此,for循环代码为:

for repo in repos:
    os.system("git clone http://github.com/{}".format(repo))
最后,我们得到列表中回购的数量并将其打印出来,我们使用
print(“有{}个回购。”.format(str(len(repos)))

完整代码为:

import os

repos=["BloodHoundAD/BloodHound.git", "GhostPack/Seatbelt.git", "GhostPack/SharpUp.git", "yeyintminthuhtut/Awesome-Red-Teaming.git",
"byt3bl33d3r/DeathStar.git", "byt3bl33d3r/CrackMapExec.git", "Cn33liz/p0wnedShell.git", "EmpireProject/Empire.git",
"danielmiessler/SecLists.git", "laramies/theHarvester.git"]

for repo in repos:
    os.system("git clone http://github.com/{}".format(repo))


print ("There are {} repos.".format(str(len(repos))))

我认为字符串格式不需要转换为字符串。另外,
子流程
应该优先于
操作系统
。您知道将子流程与repos数组列表一起使用的正确方法是什么吗?