简体   繁体   English

有什么方法可以将 Powershell、Python 脚本转换为 Bash 脚本?

[英]Is there any way to convert Powershell,Python script to Bash script?

I have developed multiple PowerShell scripts for Windows OS我为 Windows 操作系统开发了多个 PowerShell 脚本

Check Memory utilization Changing service state Retrieving User Information.检查内存利用率 更改服务状态 检索用户信息。

i want to develop the same scripts for Linux and Mac OS, is there any way i can use existing powershell scripts.我想为 Linux 和 Mac OS 开发相同的脚本,有什么方法可以使用现有的 powershell 脚本。

You might find this link helpful:您可能会发现此链接很有帮助:

https://www.phillipsj.net/posts/using-powershell-scripts-from-bash https://www.phillipsj.net/posts/using-powershell-scripts-from-bash

It gives you a guide on how to install power shell and then some examples on how to run the powershell scripts in bash.它为您提供了有关如何安装 powershell 的指南,以及一些有关如何在 bash 中运行 powershell 脚本的示例。

I suppose there is not an automagical way to convert ps to bash nor to use ps scripts natively on Linux.我想没有一种自动将 ps 转换为 bash 的方法,也没有在 Linux 上本地使用 ps 脚本的方法。 You have to rewrite them, using bash, python, perl or whatever scripting language you prefer and considering that windows works in a different way.你必须重写它们,使用 bash、python、perl 或任何你喜欢的脚本语言,并考虑到 windows 以不同的方式工作。

You can call your python script in the .bat file by doing the following in your .bat file:您可以通过在 .bat 文件中执行以下操作来调用 .bat 文件中的 python 脚本:

"python.exe path" "the path for your python script" and then save it as a .bat file. “python.exe 路径”“python 脚本的路径”,然后将其另存为 .bat 文件。

You can get the executable python path by typing "where python" on your cmd.您可以通过在 cmd 上键入“where python”来获取可执行的 python 路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM