- Every script file ends with #! At the beginning, it is used to tell the shell which interpreter needs to be specified for execution (have you found any errors? Yes, the exclamation mark is! Not!);
- When an interpreter executes this file, this line is treated as a comment line
- So you understand that this line is for the shell to identify and call an interpreter to execute the following command statements. After the interpreter is determined, this line is a comment line for the interpreter
- #! The path attached afterwards is the binary program path used to interpret the script commands ;
- If there is no such line, that is to say we don’t write it, we use the bash interpreter by default when executing with " . /File ". When we have commands that bash can interpret in the script, the file executes normally; but when we When the script is python expect or other languages, an error will be reported if the file cannot be executed, and a Command not found warning will be obtained
- In summary:
- Use . command or source command we must add #!(path)
- If it is a bash interpreter, we add: #!/bin/bash
- Bash has command statements such as: ip ad sh, ping, echo, grep, while, until, for, etc.
- If it is a python interpreter, we add: #!/usr/bin/python
- If it is an expect interpreter, we will add: #!/usr/bin/expect
- Expect has commands such as: spawn, expect, send, exp_continue, etc.
- If it is a perl interpreter, we add: #!/usr/bin/perl
… - Note:! Cannot be in Chinese!
- Note: The path name must be correct, otherwise you will get a Command not found warning
- If it is the " interpreter file" command, then the first line can be omitted , for example:
- bash file.sh
- expect file.exp
- pathon file, py
- But I suggest you add it
Okay, get out of class is over! Leave a message with questions