我可以让脚本互相调用吗?加壳器如何使编写许多脚本成为可能?

Can I have a scripts call each other? How does packer make it possible to compose many scripts?

我还没有找到这方面的任何例子,所以我不确定它是否可行。

我想要其他打包程序脚本使用的实用程序脚本。脚本之间可以直接调用吗?

例如,如果在 script1.ps1 内部调用 script2.ps1(通过相对路径),它会在那里吗?加壳器会将两个文件上传到同一位置并且脚本可以相互访问吗?

{
  "script": "./script1.ps1",
  "type": "powershell"
},
{
  "script": "./script2.ps1",
  "type": "powershell"
}

如果我将它们放在像这样的 diff 文件夹中,我是否能够像 ./../subdir/script2.ps1 一样访问 script1 中的 script2?

{
  "script": "./otherdir/script1.ps1",
  "type": "powershell"
},
{
  "script": "./subdir/script2.ps1",
  "type": "powershell"
}

是的,你当然可以这样做,尽管我不确定 运行 像你这样的两个 Powershell 条款的真正优势是什么。

对于第一个脚本调用第二个脚本,第二个脚本必须已经存在于目标机器上。您可以执行以下操作:

{
    "type": "file",
    "source": "./script2.ps1",
    "destination": "C:/Windows/Temp/script2.ps1"
},
{
    "script": "./script1.ps1",
    "type": "powershell"
}

script1 调用 script2 然后删除它:

& C:\Windows\Temp\script2.ps1
Remove-Item C:\Windows\Temp\script2.ps1