bash - 从 Windows 的某个目录中启动 bash

标签 bash cmd windows-subsystem-for-linux

我正在尝试启动“/mnt”目录中的 Bash.exe。

以下命令可以正确启动 bash:

C:\Windows\Sysnative\bash.exe

我有以下 .bat 文件:

C:\Windows\Sysnative\bash.exe -c "cd /mnt/"

不幸的是,这没有任何作用。这同样适用于:

C:\Windows\Sysnative\bash.exe --cd "/mnt/"

最佳答案

尝试:

C:\Windows\Sysnative\bash.exe -c "cd /mnt/ ; exec bash"

这将启动一个 Bash 进程,该进程 cds 到“/mnt/”,然后将其自身替换为在“/mnt”目录中运行的新的(交互式)Bash 进程。

上面的代码仅经过轻微测试,可能满足也可能不满足您的要求。有关替代方案,请参阅 run bash command in new shell and stay in new shell after this command executes以及其中的“链接”页面。

关于bash - 从 Windows 的某个目录中启动 bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52666709/

相关文章:

linux - Windows sublinux - 获取调用 linux 的 windows 路径

linux - windows子系统Linux在终端中找不到文件

windows - Git 命令在 Windows CMD 中不起作用

windows - Dos 目录掩码,需要 "*.xxx"而不是 "*.xxxzz"

linux - 使用 bash、sed 或 awk 拆分 CSV 文件并排除输出中的列

用于查找前一个日历日的 Bash 逻辑

windows - 将shell函数移植到cmd.exe : Is it possible to automatically source scripts on startup?

c - Syslog 目录不存在

python - 通过 bash 替换单个 CSV 字段中的额外双引号

bash - 不 "pollute"环境的可来源脚本?