The script in Linux starts with #!, which tells the system which interpreter the script file should be executed by. When executing a script, the operating system will read the shebang line and call the corresponding interpreter to interpret and execute the commands in the script file. It should be noted that the script file needs to have executable permissions. You can use the chmod x script.sh command. Grant execution permissions.
The operating system of this tutorial: Linux5.18.14 system, Dell G3 computer.
In Linux, script files usually start with a specified interpreter, which is used to tell the system which interpreter to use to execute the script. Common scripts start with the following:
1. Bash script: starting with #!/bin/bash means using Bash as the interpreter.
#!/bin/bash# 脚本内容...
2. Python script: starting with #!/usr/bin/env python or #!/usr/bin/python means using the Python interpreter.
#!/usr/bin/env python# 脚本内容...
3. Perl script: starting with #!/usr/bin/perl means using the Perl interpreter.
#!/usr/bin/perl # 脚本内容...
4. Shell script (other Shell): Start with the path corresponding to the Shell interpreter, for example #!/bin/sh means using the sh interpreter.
#!/bin/sh # 脚本内容...
These scripts start with #! and are called "shebang" (also called Hashbang), which tells the system which interpreter the script file should be executed by. When executing a script, the operating system reads the shebang lines and calls the appropriate interpreter to interpret and execute the commands in the script file.
It should be noted that the script file needs to have executable permissions, which can be granted through the chmod x script.sh command. Then, you can run the script file directly and the system will automatically use the specified interpreter to execute the commands in it.
The above is the detailed content of What does a script in linux begin with?. For more information, please follow other related articles on the PHP Chinese website!