What does a script in linux begin with?

尊渡假赌尊渡假赌尊渡假赌
Release: 2023-07-10 16:21:19
Original
2476 people have browsed it

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.

What does a script in linux begin with?

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# 
脚本内容...
Copy after login

2. Python script: starting with #!/usr/bin/env python or #!/usr/bin/python means using the Python interpreter.

#!/usr/bin/env python# 
脚本内容...
Copy after login

3. Perl script: starting with #!/usr/bin/perl means using the Perl interpreter.

#!/usr/bin/perl
# 脚本内容...
Copy after login

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
# 脚本内容...
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!