shell 中调用其余的脚本

方法有三种:bash

1 使用sourcespa

2 使用 .file

3 使用sh方法

简单实验:脚本

first.shco

#!/bin/bash
echo 'your are in first file'参数传递

 

second.shbackground

#!/bin/bash
echo 'your are in second file'参数

source first.sh // . first.sh // sh first.shab

 

执行结果:

your are in second file
your are in first file

 

如今讨论关于参数传递:

first.sh

#!/bin/bash
echo 'your are in first file'
echo "${0} ${1}"

second.sh

#!/bin/bash
echo 'your are in second file'
echo "${0} ${1}"

. first.sh ${2} //source first.sh

执行:./second.sh abc 123

your are in second file
./second.sh abc
your are in first file
./second.sh 123

 

改变second.sh

second.sh

#!/bin/bash
echo 'your are in second file'
echo "${0} ${1}"

sh first.sh ${2} 

执行:

./second.sh abc 123

结果:

your are in second file
./second.sh abc
your are in first file
first.sh 123

因此在调用的那个脚本须要传递参数的时候仍是要注意选对方法的

相关文章
相关标签/搜索