首页 > 解决方案 > 适用于 Linux 的 Windows 子系统 - 在启动时将参数传递给命令

问题描述

我目前正在研究如何利用 wsl 来满足我的开发需求。为了做到这一点,我创建了 wsl 以便它与 systemd 一起使用,以启用 microk8s 和其他依赖于 systemd 的服务。

现在这给我带来了一个问题。我希望能够启动 wsl 并导航到我当前所在的目录。现在

wsl /bin/bash

会这样做。不幸的是,bash 将绕过我的 /etc/profile.d 脚本,这将导致我的 init 进程成为一个 wsl 设置而不是 systemd。

现在我可以轻松地将参数传递给 wsl 内的任何 shell 脚本,正如您所期望的那样

例子.sh

echo "Your argument is $1"
example.sh Hello World

# Output
# Your argument is Hello

但由于某种原因,我无法从外面做同样的事情

wsl /path/example.sh Hello
bash -c /paht/example.sh

所有这些调用都不会导致 $1 包含任何内容。任何想法我怎么能做到这一点?

标签: bashwindows-subsystem-for-linuxwsl-2

解决方案


推荐阅读