linux - 如何在 Linux 上使用 Powershell(提升 Powershell,以管理员身份运行命令)“sudo”?
问题描述
如果你想在 Windows 的 PowerShell 上以管理员身份运行命令,你可以这样写:
Start-Process foo -Verb RunAs -ArgumentList '...'
但这在 Linux 上是不可能的。Powershell 会返回以下错误:Start-Process: The parameter '-Verb' is not supported for the cmdlet 'Start-Process' on this edition of PowerShell.
确实,根据Powershell 在线文档,“ [ - Verb]参数不适用于非 Windows 系统”,因此无法在 Linux 上像这样以管理员身份运行 Powershell。
我的问题很简单:如何在 Linux 上提升 Powershell 权限?如何sudo ...
在 Linux 上使用 Powershell 模拟 BASH?我知道你可以用 bash 和类似的东西来解决这个问题sudo pwsh -Command '...'
,但我正在寻找一种“100% PowerShell”的方法来做到这一点。
提前感谢您的回复。
PS:“PowerShell”是指最新的“PowerShell 7”。
解决方案
使用 sudo pwsh -c:
PS> (sudo pwsh { gci -r /opt/tomcat/ .sh | ? name -like 'startup ' }).fullname /opt/tomcat/bin/startup.sh
推荐阅读
- bigdata - 当公司使用开发/登台/生产环境进行软件开发时,如何调用登台表
- html - ASP.NET MVC 表行,包括来自模型的文本链接
- api - 如何在 Windows 机器上设置 Gravitee.io
- mongodb - MongoDB .msi 安装程序无法在 Windows 10 上运行
- jenkins - 詹金斯 - 矩阵作业 - 不同奴隶上的变量相互覆盖?
- android - 如何开启usb调试模式?
- php - 在 wordpress 数据库中添加带有数据的自定义行
- python - 在迭代文件夹结构时匹配文件中的文本
- python-2.7 - 使用python将一系列ppm图像转换为视频
- flutter - 当键盘弹出时,将包含小部件的 TextField 移动到可查看区域,而不管底部的另一个小部件