shell脚本里相互调用的方法

前言

shell写脚本通常可以模块化,也可以功能化,例如test1.sh完成一个独立功能,test2.sh也完成一个独立的功能,但是需要test1.sh作为前提,因此为了节省执行时间,不是用crontab傻瓜似的等待,我们可以在test1.sh里调用test2.sh执行,效率会更高,这里仅仅介绍两种在一个脚本里调用另外一个脚本的方法

脚本间调用

首先,简单的写两个测试脚本

test1.sh :

#!/bin/bash

echo "the first scripts"

test2.sh :

#!/bin/bash

调用 test1.sh

echo "second scripts"

使用source

代码:

#!/bin/bash

source ./test1.sh

echo "second scripts"

效果:




使用bash

代码:

#!/bin/bash

bash ./test1.sh

echo "second scripts"

效果:


 

posted @ 2013-05-10 20:26  坚固66  阅读(319)  评论(0编辑  收藏  举报