shell中调用另外的脚本文件的两种方法

软件和网站开发以及相关技术探讨
回复
头像
yonsan
帖子: 887
注册时间: 2005-07-01 18:56
来自: 广州市

shell中调用另外的脚本文件的两种方法

#1

帖子 yonsan » 2005-08-08 11:25

脚本 first (测试示例1)

代码: 全选

#!/bin/bash
echo 'your are in first file'
问) 在当前脚本文件中调用另外一个脚本文件?
方法一: 使用source
脚本 second (测试示例2)

代码: 全选

#!/bin/bash
echo 'your are in second file'
source first
方法二: 使用.
脚本 second (测试示例3)

代码: 全选

#!/bin/bash
echo 'your are in second file'
. first
I will be back!
emacsnw
帖子: 5
注册时间: 2005-09-06 16:48

Re: shell中调用另外的脚本文件的两种方法

#2

帖子 emacsnw » 2005-09-06 17:09

source filename和 . filename 应该是同一回事,都是在*当前*shell环境中执行脚本。也可以使用sh filename,那是在当前shell的子shell中执行脚本。

yonsan 写了:脚本 first (测试示例1)

代码: 全选

#!/bin/bash
echo 'your are in first file'
问) 在当前脚本文件中调用另外一个脚本文件?
方法一: 使用source
脚本 second (测试示例2)

代码: 全选

#!/bin/bash
echo 'your are in second file'
source first
方法二: 使用.
脚本 second (测试示例3)

代码: 全选

#!/bin/bash
echo 'your are in second file'
. first
回复