",linux,bash,powershell,windows-subsystem-for-linux"/>

首页 > 解决方案 > WSL,使用“wsl --exec”运行 linux 命令" 或 "wsl --"

问题描述

wsl -h显示以下内容:

    --exec, -e <CommandLine>   Execute the specified command without using the default Linux shell.
    --   Pass the remaining command line as is.

“不使用默认的 Linux shell”是什么意思(即,如果不是默认的 shell,它还会使用什么!?)?

另外,作为一个例子,我现在有三种可能的方式来ls从我的 PowerShell 提示符运行 Linux(即,这不会被Get-ChildItem别名为ls,而是通过 WSL 的 Linux 命令):

PS C:\> wsl -e ls   # Alternatively,  wsl --exec ls
PS C:\> wsl -- ls
PS C:\> wsl ls

但是所有的输出似乎都是一样的。您将如何解释从 PowerShell 提示符运行 WSL Linux 命令的这三种方式之间的区别?

标签: linuxbashpowershellwindows-subsystem-for-linux

解决方案


我认为这意味着 wsl 运行命令directly,而不是产生一个 shell 进程来运行命令。

例如,如果我运行:

wsl -e sleep 10

从另一个终端,我有:

root      1482     1  0 11:32 tty3     00:00:00 /init
ubuntu    1483  1482  0 11:32 tty3     00:00:00 sleep 10

我们可以看到/init是 的父级sleep 10,中间没有外壳。


推荐阅读