shell实例(十五) ----exec命令

1.一个exec自身的脚本

#! /bin/sh
echo
echo "This line appears ONCE in the script,yet it keeps echoing."
echo "The PID of this instance of the script is still $$."
echo "====================Hit Contrl + C to exit ================="

sleep 2
exec $0
echo "This line will never echo!"
exit 0

 

2.shopt允许shell在空闲时修改shell选项,经常出现在启动文件中。

 shop -s cdspell ---------使用cd命令时,允许少量的错误

  cd /hpme ---- 应该是/home

  pwd  ----------/home

 

3.caller命令放入函数中,将显示调用该函数的调用者信息

4.type [cmd]

将给出命令的完整路径

 

5.作业控制命令

#! /bin/sh
ROOT_UID=0
E_NOTROOT=65
E_NOPARAMS=66

if [ "$UID" -ne "$ROOT_UID" ]
then
  echo "Must be root to run this script."
  exit $E_NOTROOT
fi

if [ -z "$1" ]
then
  echo "Usage:  `basename $0` find-string"
  exit $E_NOPARAMS
fi

echo "Updating 'locate' database..."
echo "This may make a while ."
updatedb /usr &
wait
locate $1
exit 0

 

6.结束自身脚本程序

#! /bin/sh
kill &&  ----------------&&相当于PID
echo "This line will not echo"

exit 0

你可能感兴趣的:(shell编程)