【问题标题】:Start bash in certain directory from Windows从 Windows 在某个目录中启动 bash
【发布时间】:2023-03-17 05:55:01
【问题描述】:

我正在尝试在“/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/"

【问题讨论】:

  • 免责声明:即使有非常相似的帖子,这不是重复的。
  • 我不使用bash.exe,但是,你试过“\”吗?
  • 斜线的格式在这个例子中已经是正确的。如果不是,它应该给出一个找不到路径的错误。
  • 您的主目录中有 .bash_profile 或 .bashrc 文件吗?
  • 没有。我的 /home 目录及其任何子目录中都没有 .bash_profile 或 .bashrc 文件。

标签: bash cmd windows-subsystem-for-linux


【解决方案1】:

试试:

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

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

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

【讨论】:

  • 这完全符合我的要求。我对其进行了测试,并且效果很好。伟大的工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-05
  • 1970-01-01
  • 2014-09-17
  • 1970-01-01
  • 1970-01-01
  • 2020-06-30
相关资源
最近更新 更多