当我在采购包含选项 `set -e` 的 bash 脚本后执行 windows 命令时,WSL 突然关闭

WSL closes abruptly when I execute a windows command after sourcing a bash script containing the option `set -e`

重现步骤。

请注意,我使用的是 WSL (Ubuntu 18) 版本 1。 Windows 版本 1909(OS 内部版本 18363.900)。

  1. 创建一个包含选项 set -e.
  2. 的虚拟 bash 脚本 foo.sh
#!/bin/bash

set -e

pwd
  1. 在 WSL 中执行以下命令。
$ source foo.sh
$ explorer.exe .

在我执行第二个命令后explorer.exe . WSL 突然关闭。

我刚试了一下,确实:当我运行explorer时,资源管理器Windows在后台打开,启动资源管理器的进程returns,退出代码为 1。不知道为什么微软智慧无穷,决定这么实现。

当然,在交互式 shell 中使用 set -e 是很疯狂的。我建议取消设置。如果,场景不是交互式的 shell(这从你的问题中并不完全清楚),但是你 运行 来自脚本内部的命令,并且你确实想坚持使用 -e , 用

启动资源管理器
explorer.exe || true

保持shell运行宁。