Ubuntu 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
更多Ubuntu相關信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2