调用WSL命令后,保持Windows终端选项卡打开
我正在尝试在 Windows终端中打开 wsl(ubuntu)选项卡,然后使用WSL在该选项卡中运行命令。我使用以下powershell命令:
wt new-tab -p "WSL (Ubuntu)" wsl echo "hallo"
问题是在echo
运行后,标签立即关闭。 有没有办法保持打开状态?
I'm trying to open a WSL (Ubuntu) tab in Windows Terminal, and then run a command in that tab using WSL. I use the following PowerShell command for that:
wt new-tab -p "WSL (Ubuntu)" wsl echo "hallo"
The problem is, after echo
has run, the tab closes immediately.
Is there a way to keep it open?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您将命令行传递到
wt.exe
,Windows终端CLI时,它是运行 的,无论您是否还指定特定的shell带有-p
的配置文件。因此,要实现您想要的东西:
。
虽然PowerShell支持这一点,但POSIX兼容的外壳(例如
bash
-WSL的默认外壳) - 不。a-次优 - 解决方案是:
注意:
莫名其妙,如Windows terminal v1.13.11431.0,
;
char。在引用的-c
参数中,需要逃脱为\;
- 否则,它将通过wt.exe
其用于打开多个 tabs/windows的分离器。以上执行指定的
echo
命令,然后使用exec
用交互式,开放的会话替换非相互交互的,自动关闭的原始Shell通过exec
。这种方法的限制是,除了更换原始外壳时,启动命令所做的任何状态都会丢失。丢失。
〜/.bashrc
,附加启动命令,然后将临时副本的文件路径传递给bash
's- rcfile
option;此后删除临时副本。When you pass a command line to
wt.exe
, the Windows Terminal CLI, it is run instead of a shell, irrespective of whether you also specify a specific shell profile with-p
.Thus, to achieve what you want:
While PowerShell supports this, POSIX-compatible shells such as
bash
- WSL's default shell - do not.A - suboptimal - workaround is the following:
Note:
Inexplicably, as of Windows Terminal v1.13.11431.0,
the
;
char. inside the quoted-c
argument requires escaping as\;
- otherwise it is interpreted bywt.exe
as its separator for opening multiple tabs / windows.The above executes the specified
echo
command first, and then usesexec
to replace the non-interactive, auto-closing original shell with an interactive, stay-open session viaexec
. The limitation of this approach is that any state changes other than environment-variable definitions made by the startup command(s) are lost when the original shell is replaced.~/.bashrc
, append your startup commands, and pass the temporary copy's file path tobash
's--rcfile
option; delete the temporary copy afterwards.