This article mainly introduces 2 methods of referencing and invoking another script file in the shell script, this article introduces the syntax of the two methods, then gives the actual usages and some places to pay attention to, the friend who needs can refer to the following
In Java,python, you can use the import method to make calls between scripts or modules, for example:
The code is as follows:
>>> Import Math
>>> Math.sqrt (4)
2.0
How do you invoke other shell scripts in the shell, or variables in other scripts, functions?
Method one:. ./subscript.sh
Method Two: source./subscript.sh
Attention:
1. Between two points, there are spaces, you must pay attention to.
2. Two scripts are not in the same directory, use absolute path
3. For the sake of simplicity, the first method is usually used
For example:
The code is as follows:
Main.sh #主脚本
Subscripts.sh #子脚本, or the script that was tuned
[Code]
[Code]
# # #subscripts. sh script contents are as follows: ###
#!/bin/bash
String= "hello,world! N
The code is as follows:
# # #main. sh script content as follows ###
#!/bin/bash
. ./subscripts.sh
Echo-e ${string}
Exit 0
Output results:
The code is as follows:
# chmod +x./main.sh
#./main.sh
hello,world!
#
Attention:
1. The scripted script can not execute permissions, the calling script must have executable permissions
2.chmod +x./main.sh #注意这里要有点, or bash scripts may not be found