How does the Linux shell call another script file


Many Linux users don't know that the shell can not only edit the script, but also call another script file on the script, including the php file. How should it be called? The following small series will introduce you to the Linux shell to call another script file, friends who do not call the script can learn.

script first (Test Example 1)

code below

#! /bin/bash

echo ‘your are in first file’

Q) Calling another script file in the current script file?

Method one: Use source

script second (test example 2)

#! /bin/bash

echo ‘your are in second file’

source first

Method 2: Use .

Script second (test example 3)

#! /bin/bash

echo ‘your are in second file’

. First

source filename and . Filename should be the same thing, both in the *current *Shell environment to execute the script. You can also use sh filename, which is to execute the script in the subshell of the current shell.

You can use the following two scripts to understand the difference between the three calling methods:

#! /bin/bash


echo “PID for before exec/source/fork:$$”

export A

echo “ $A is $A”

case $1 in


echo “using exec…”

exec. / ;;


echo “using source…”

. . / ;;


echo “using fork by default…”

. / ;;


echo “PID for after exec/source/fork:$$”

echo “ : $A is $A”

#! /bin/bash

echo “PID for $$”

echo “ get $A=$A from”


export A

echo “ $A is $A”


$ . /

PID for before exec/source/fork:5845364 $A is B

using fork by default…

PID for 5242940 get $A=B from $A is C

PID For after exec/source/fork:5845364 $A is B

$ . / exec

PID for before exec/source/fork:5562668 $A is B

using exec…

PID for 5562668 get $A=B from $A is C

$ . / source

PID for before exec/source/fork:5156894 $A is B

using source…

PID for 5156894 get $A=B from $A is C

PID for after exec/source/fork:5156894 $A is C


The above is the introduction of the Linux shell call script file. When you are calling a php file, you don't have to use php, you can also use shell commands.

Copyright © Windows knowledge All Rights Reserved