ygw_ycf 发表于 2004-11-14 20:49:45

she l l 中如何引用其他文件中的函数

我看到 FC3 /e t c /init.d 中有个fu n c ti o n,里面说明说是一些函数---供其他she l l s c ri p t 函数调用的
另外谁知道这些函数是干什么用的
如:
status() {
local base=${1##*/}
local pid

# Test syntax.
if [ "$#" = 0 ] ; then
echo $"Usage: status {program}"
return 1
fi

# First try "pidof"
pid=`pidof -o $$ -o $PPID -o %PPID -x $1 || \
      pidof -o $$ -o $PPID -o %PPID -x ${base}`
if [ -n "$pid" ]; then
         echo $"${base} (pid $pid) is running..."
         return 0
fi

# Next try "/var/run/*.pid" files
if [ -f /var/run/${base}.pid ] ; then
         read pid < /var/run/${base}.pid
         if [ -n "$pid" ]; then
               echo $"${base} dead but pid file exists"
               return 1
         fi
fi
# See if /var/lock/subsys/${base} exists
if [ -f /var/lock/subsys/${base} ]; then
echo $"${base} dead but subsys locked"
return 2
fi
echo $"${base} is stopped"
return 3
}

MichaelBibby 发表于 2004-11-14 22:22:34

如果一个脚本中都是函数,没有其它的命令的话,可以这样实现:
file function.sh
#!/bin/bash
call()
{
      echo "this is funcion1 -- call"
}
file func_call.sh
#!/bin/bash
. ./function1.sh
call
然后执行func_call.sh文件:
$ chmod +x func_call.sh
$ ./func_call.sh


至于脚本function.sh中另有其它操作时,该如何调用脚本中的函数而不执行其它操作,小弟还不明白,还请知道的朋友赐教。 :-)
页: [1]
查看完整版本: she l l 中如何引用其他文件中的函数