有没有办法为 Cygwin 中的某个位置别名为 shebang?
我有一些经常在 Windows(cygwin)和 Linux 中使用的脚本,我想让这些脚本在这两种环境中都可执行。有没有办法为我的 python 安装位置设置别名,例如,这样
#!/usr/bin/python
仍然可以找到我的 python 安装,尽管就 cygwin 而言,它位于 /cygdrive/c/Python26/python< /代码>?
I have some scripts that I often use in both windows(cygwin) and linux, I'd like to make the scripts executable in both environments. Is there a way to alias the location of my python installation, for example so that
#!/usr/bin/python
will still find my python installation, even though, as far as cygwin is concerned, it is located at /cygdrive/c/Python26/python
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需通过 Cygwin 的
setup.exe
安装 Python,它将位于/usr/bin
中。或者在两个系统上创建符号链接,例如在
/usr/local/bin/python
中,并在 shebang 中使用它。或者编写一个安装脚本,在安装 Python 脚本时调整
#!
行。请注意,如果您的
/cygdrive/c/Python26/python
(C:\Python26\python
) 是本机 Windows Python 安装,则使用它的脚本将无法使用 Cygwin 风格的路径。Just install Python via Cygwin's
setup.exe
, and it will be in/usr/bin
.Or create symbolic links on both systems, for example in
/usr/local/bin/python
, and use that in the shebang.Or write an installation script that adjusts the
#!
line in your Python scripts as it installs them.Note that if your
/cygdrive/c/Python26/python
(C:\Python26\python
) is a native Windows Python installation, scripts using it won't be able to use Cygwin-style paths.来替换 shebang 行。
将 /cygdrive/c/Python26/python 放入 PATH 变量中,并假设 cygwin 可以运行该版本的 python
Put /cygdrive/c/Python26/python in your PATH variable, and replace the shebang line with
assuming that cygwin can run that version of python.