In Java and python, you can use the import method to call scripts or modules. For example:
>>> import math>>> math.sqrt(4)2.0
In Shell, how do I call other shell scripts, or variables and functions in other scripts?
Method 1:../Subscript. Sh
Method 2:Source./Subscript. Sh
Note:
- There is a space between two points. Please note that.
- The two scripts are not in the same directory and must use an absolute path.
- For simplicity, the first method is usually used.
For example:
- Main. Sh # Main script
- Subscripts. Sh # subscript, or called script
### Subscripts. Sh script content :####! /Bin/bashstring = "Hello, world! \ N"
### Main. Sh script content ####! /Bin/bash ../subscripts. shecho-e $ {string} exit 0
Output result:
# chmod +x ./main.sh# ./main.shHello,World!#
Note:
- The script to be called can have no execution permission, and the script to be called must have the executable permission.
- Chmod + X./Main. Sh # Note that there is something here, otherwise the bash script may not be found.