我需要创建一个集成脚本来设置一些环境变量,使用wget下载文件并运行它。是否可以编写一个在bash/shell和PowerShell中运行的脚本?
挑战在于它需要是可以在Windows PowerShell和bash/shell上运行的SAME脚本。
这是shell脚本:
#!/bin/bash
# download a script
wget http://www.example.org/my.script -O my.script
# set a couple of environment variables
export script_source=http://www.example.org
export some_value=floob
# now execute the downloaded script
bash ./my.script
这是在PowerShell中的同样的事情:
wget http://www.example.org/my.script -O my.script.ps1
$env:script_source="http://www.example.org"
$env:some_value="floob"
PowerShell -File ./my.script.ps1
所以我想如果不知何故这两个脚本可以合并,并成功地在任何平台上运行?
我一直在试图找到一种方法,把它们放在同一个脚本中,并让bash和PowerShell.exe忽略错误,但一直没有成功。
任何猜测?
你看过这个吗? http://stackoverflow.com/questions/17510688/single-script-to-run-in-both-windows-batch-and-linux-bash – idjaw
你可以使用PowerShell v6-alpha –
哇,如果PowerShell v6可以做到这一点,这将是令人印象深刻的。随着bash提供最新版本的Windows 10,可能会解决您的问题吗? –