Follow the Runoob website tutorial to learn the notes
Like other languages, the shell can also contain external scripts. This makes it easy to encapsulate some common code as a standalone file. Shell files contain syntax in two forms
- . FileName #也就是一个英文句号后面跟着想要包含的文件名, notice that there is a space separating the middle
- SOURCE filename
While experimenting with a problem, the second file contains forms that are not available in SH, and both of these file inclusions are available in bash
Instance
Create two shell script files
The test1.sh code is as follows:
#!/bin/bash# Author: Rookie Tutorial # Url:www.runoob.comurl="http://www.runoob.com"
The test2.sh code is as follows:
#!/bin/bash# Author: Rookie Tutorial # url:www.runoob.com# use the. Number to refer to Test1. SH File: /test1. SH # or use the following include file code # source. /test1. SH Echo " Novice Tutorial Official website address: $url "
Next, we add executable permissions for test2.sh and execute:
chmod +x test2. SH $ . /test2. SH Novice Tutorial Official website address: http: // www.runoob.com
Note: The included file test1.sh does not require executable permissions
Run a python script in a shell script
Try to run the Python script in the shell script, if the Python script contains the shell's illegal statements, the above mentioned two methods are not possible, this may indicate that the above method is only for Shell script calls. It is also convenient to run Python scripts in shell scripts in two ways:
- Writing Python finename.py in a shell script
- Add executable permissions to filename.py before writing to the shell script./filename.py
Description: In fact, these two methods are the two ways to run Python in the terminal, now just write in the script to let it execute line by row. Try the second method above failed, check whether to add #!/usr/bin/python (or other path) to the first line of the Python script
Shell Scripting Learning-file contains