ubuntu shell编程中载入函数或者变量的方法

shell编程中调用别的文件定义的函数或者变量的方法

#!/bin/sh

if [ -r backfunc ] ; then
. /home/fef/shell/backfunc  #"."后面有个空格,并且backfunc必须使用绝对路径!!
else
	echo "`basename $0` cannot locate backfunc file"
fi

echo -n "Enter the code name: "
if [ "$CODE" != "$_CODE" ] ; then
	echo "Wrong code... exiting... will use default"
	exit 1
fi

echo "The environment config file reports"
echo "FULL backup Required	: $_FULLBACKUP"
echo "$LOGFILE"



其中backfunc文件内容如下:

#!/bin/sh

# name: backfunc
# config file that holds the defaults for the archive systems
_CODE="comet"
_FULLBACKUP="yes"
_LOGFILE="/logs/backup"
_DEVICE="/dev/rmt/On"
_INFORM="yes"
_PRINT_STATS="yes"

最后运行上面的脚本$:sh readfunc comet

得到的结果:

The environment config file reports
FULL backup Required : yes

发布了53 篇原创文章 · 获赞 12 · 访问量 50万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章