我怎么能把.sh文件和Cygwin?

问题描述:

我想在Cygwin中运行一个长rsync命令,双击Windows中的.sh文件。它必须在文件的包含目录(例如/ cygdrive / c / scripts /)中启动,以使相对路径工作。有人得到这个工作吗?

I'd like to run a long rsync command in Cygwin by double clicking on a .sh file in Windows. It must start in the file's containing directory (e.g. /cygdrive/c/scripts/) so that relative paths work. Anyone gotten this to work?

注意:我刚刚发现 chere ,一个管理Windows上下文菜单的Cygwin软件包(Bash Prompt Here)。它可能有一些线索。

Note: I've just found chere, a Cygwin package that manages Windows context menus (Bash Prompt Here). It might have some clues.

好的,我发现了一些有用的东西。将批处理文件关联为Vladimir建议不起作用,但bash参数是关键。

Ok, I've found something that works. Associating a batch file as Vladimir suggested didn't work, but the bash arguments were key.

短而甜:与此命令关联:C:\cygwin\bin\bash.exe-li%1%*

Short and sweet: associate with this command: "C:\cygwin\bin\bash.exe" -li "%1" %*

长版本,如果您不知道如何:

Long version if you don't know how:


  1. 在资源管理器中,转到工具/文件夹选项/文件类型。

  2. 我已经有一个SH条目的Bash脚本。如果没有,请点击新建并输入SH创建一个。

  3. 选择SH扩展程序,点击高级。

  4. 选择打开操作,然后点击修改(或创建操作)。

  5. 这是要使用的命令:C:\cygwin\bin\bash。 exe-li%1%* 。请注意,如果没有 -li ,它会在我的脚本上撤回命令未找到。

  1. In Explorer, go to Tools/Folder Options/File Types.
  2. I already had an SH entry for Bash Script. If you don't have one, click New and enter "SH" to create one.
  3. With the SH extension selected, click Advanced.
  4. Choose the "open" action and click edit (or create the action).
  5. This is the command to use: "C:\cygwin\bin\bash.exe" -li "%1" %*. Note that without the -li, it was returing "command not found" on my scripts.

也可以向 PATHEXT 环境变量添加 SH

You may also want to add SH to your PATHEXT environment variable:

WinKey +暂停/高级/环境变量/系统变量/ PATHEXT

WinKey+Pause / Advanced / Environment Variables / System Variables / PATHEXT

感谢您的帮助,各位!