我正在尝试启动 wsl 并注入 sh 以在启动时运行,如下所示:
wsl --cd /path/to/script/ -e sh script.sh
我得到了这个:
./script.sh: 48: go: not found
在脚本的第 48 行我有这个:
go build && ./hub-api
如果我打开 wsl 并运行脚本,一切都会正常,但我无法通过单个命令运行它。
我需要做什么才能在单“行”上运行脚本?
谢谢。
wsl --cd /path/to/script/ -e sh script.sh
和从交互式会话运行 sh script.sh
之间的区别在于,第二种情况是在登录 shell 中运行。
这意味着第一种方法不会读取所有点文件,而第二种方法则会读取。
一个简单的解决方案是添加
-l
选项来强制登录 shell:
wsl --cd /path/to/script/ -e sh -l script.sh