First of all, the poster’s understanding is somewhat wrong. #!/usr/bin/env python is the interpreter of the specified script, and +x gives execution permissions to the owner, group members and others. There is no connection between the two. Secondly, you can also write a simple script and execute it every time you use vi to open the .py file, but I think it is not necessary. After all, it is just a matter of chmod command.
I rarely write scripts for direct execution, so I haven’t thought about this function. However, there are still a few ideas.
I don’t know what editor the questioner is using, but I usually use
vim
,当然下面我说的方法在emacs
and it works.Open your
vim
配置文件,默认一般是~/.vimrc
, so I usually edit it like this:Then add this sentence at the end:
This sentence means that if the first line of your file starts with
#!
, it will be given executable permission by default.After adding, save and exit, and then you edit a
python
文件试试,应该是默认加执行权限了,我在ubuntu
和debian
and all tests pass.If you are using
emacs
, you may wish to refer to this article!First of all, the poster’s understanding is somewhat wrong. #!/usr/bin/env python is the interpreter of the specified script, and +x gives execution permissions to the owner, group members and others. There is no connection between the two. Secondly, you can also write a simple script and execute it every time you use vi to open the .py file, but I think it is not necessary. After all, it is just a matter of chmod command.
pythonxxx.py
Or you can write a script called
run
and the content inside isThen add execution permission,
run xxx.py
You can modify this script
For example, if the suffix is py, execute Python, if it is c, use gcc, if it is .cpp, use g++..
"+x" is to increase the executable permissions, and "#!/usr/bin/env python" is which interpreter to use to run your script.
Set umask in your Linux environment and add x to yourself by default, such as setting it to 766