#/bin/python是运行什么命令的?
#/bin/python是运行什么命令的?求大牛详解。。。
初学Python,练习的时候遇到这个,被鄙视,呜呜~~~~~~~~~~~~~~恨没姿势,求涨~~
回复内容:
首先,楼主,你打漏了一个字符,正确的是#!/bin/python
要了解这行是干啥用的,得先了解一个“魔数(magic number)”的概念。
每一种文件,在文件开头,都有一个标识文件类型的字节序列,标识这个文件是什么类型的。这个字节序列叫““魔数”。
像unix下的脚本,这个魔数就是"#!"。这个魔数的英文名叫“Shebang”。
操作系统的文件解释器在加载文件时,先要判断文件是什么类型的,然后再加载特定的文件解释器,来解读这个文件。操作系统的文件解释器判断的依据,就是看这个魔数。
所以,当看到"#!"时,操作系统的文件解释器知道这是一个“脚本”。
那具体用哪一种脚本解释器呢?它继续读。
结果发现/bin/python。
也就是要用/bin/python 这个路径下的一个叫“python”的解释器来解释这个文件。
于是操作系统的文件解释器就加载了这个python解释器。 然后操作系统的文件解释器任务就完成了。
当python解释器被加载运行后,它自己来解释这个文件。
这时,它看到第一行: #!/bin/python
它认得一开头的#是标记注释行开始的记号,所以它认为这是一行注释,就直接跳过。
然后开始执行后续的真正的python指令。
综上,这一行,被两个层次的解释器以不同的形式解释。 这就是一行注释!
在#后面加上!才是解释器定义。 这是你在linux/unix系统下运行一个脚本的时候,告诉系统用什么解释器来运行脚本用的
比如你执行一个脚本
$ ./script
比如,#!/bin/python3 是定义Python3位置的。
我一般这么写,#!/use/bin/env python
这样可以让系统协助寻找Python解释器,可以在多个系统里面通用。 你用的什么教材?换一本吧,没解释这句的书就不用看了 提醒 UNIX系统 用 /bin/python 来解释执行这个脚本
head -1 abc.sh #! /bin/bash

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.
