数n,则等待进程n结束。
#cat waitdemo
echo “This is a new file”
(sleep 5; date)&
wait
echo “the file terminate”
执行结果:
This is a new file
April 20 10:08:26 BJT 2002-04-20
The file terminate
6) trap:中断处理命令
trap 命令表 中断信号表
#cat trapfile
trap echo ‘ This is INT 2’ 2
trap echo ‘ This is INT 3’ 3
for I in /bin /bin/usr
do
echo $I
done
下面程序实现scan:扫描当前目录下的每一个子目录,并执行用户提交的命令:
d=`pwd`
for i in *
do
if test –d $d/$i
then
cd $d/$i
while echo “$i:”
trap exit 2
read x
do trap : 2 ; eva l $x; done
fi
done
7)点命令 .
在bsh利用 . 命令执行一个命令时,不创建子进程。(csh中用source)
8)空命令:不做任何事情
下面程序dircmp测试当前目录与指定目录是否含有相同文件数
if test $# -ne 1 then
echo “Usage:dircmp dirname”
exit 1
else if test !-d $1 then
echo “\”$1\” is not a directory”
exit 1
else
this = `ls –l |grep ‘^-’ | wc –l `
that = `ls –l $1 |grep ‘^-’ | wc –l `
if test $this –ne $that then
echo “Current directory and \”$1\” do not match”
else
echo “Current directory and \”$1\” have same number of files”
fi
fi
fi
#dircmp abc
“abc” is not a directory
1) $chmod u+x dircmp
$./dircmp /usr/bin
2) $sh dircmp
3) $sh < dircmp
4) $ . dircmp(用点命令执行程序,不创建子进程)
%source dircmp(csh中)