Original: https://www.runoob.com/linux/linux-shell-include-file.html
And other languages, Shell may also include an external script. This makes it easy to package some common code as a separate file.
Shell syntax file contains the following:
. Filename # Note the dot (.) And filename middle of a space
or
source filename
Examples
Create two shell script files.
test1.sh code is as follows:
#!/bin/bash # Author: rookie Tutorial # Url: www.runoob.com url="http://www.runoob.com"
test2.sh code is as follows:
#!/bin/bash # Author: rookie Tutorial # Url: www.runoob.com # Use. To cite test1. SH file . ./test1.sh # Include files or use the following codes # source ./test1.sh echo " rookie tutorial official website address: $ url "
Next, we add executable permission to test2.sh and execute:
$ Chmod . + Test2 the X- SH $. / Test2. SH rookie tutorial official website address:: HTTP // www.runoob.com
Note: The file does not need to be included test1.sh executable permission.