昨天我遇到了 git execute bit bash script怪癖 - 要求:
git update-index --add --chmod=+x scriptname.sh
我觉得很奇怪,甚至有可能陷入这种情况。 (即创建了一个您无权运行的脚本文件)。
如果我已经创建了一个 shell 脚本 - 当然我可以在 shell 执行权限的权限下运行它。为什么它需要自己的执行权限位?
我的问题是:如果只能执行 Windows 批处理脚本,为什么 bash 脚本需要执行位?
最佳答案
要运行脚本,您在类 unix 系统中有两种选择。第一个选项是使用脚本作为参数直接调用解释器。
# run a bash script
bash test.sh
# run a python scripts
python test.py
第二个选项是将您的文件标记为可执行文件,使用执行位并在这样的调用之后...
# sample bash
./test.sh
# sample python
./test.py
...您的系统会尝试为您找到合适的解释器。为此,使用了脚本的第一行“shebang”。
bash 示例:
#!/bin/bash
# points to the installed bash interpreter - bash example
Python 示例:
#!/usr/bin/python
# points to the installed python interpreter
对于您的问题,Windows 仅使用文件扩展名来检测可执行文件。
关于linux - 如果只能执行 Windows 批处理脚本,为什么 bash 脚本需要执行位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35502459/