|
倒,标题写错。。。。。。。改不了了。。。。。。。。。。应该为
[color="Red"]请教有关INT与trap的问题
在看beginning linux programmingk( linux程序设计第三版)
书中第二章 shell编程 有一个代码,执行出错。
执行结果如下:
把代码中“trap INT”改为“trap 2”即可以执行,请教这是为什么?
还有,echo creating file /tmp/my_tmp_file_$$中,$$是怎么生成的?为什么生成?请指教。
代码如下:
###########执行结果#############
# ./_trap
creating file /tmp/my_tmp_file_7456
Press interrupt (Ctrl-C) to interrupt....
File exists
File exists
The file no longer exists
trap: usage: trap [-lp] [arg signal_spec ...]
##############################
##############代码如下,红色的为修改的地方###############
#!/bin/sh
trap 'rm -f /tmp/my_tmp_file_$$' INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_tmp_file_$$
echo " ress interrupt (Ctrl-C) to interrupt...."
while [ -f /tmp/my_tmp_file_$$ ]; do
echo File exists
sleep 1
done
echo The file no longer exists
[color="Red"]trap INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_tmp_file_$$
echo " ress interrupt (Ctrl-C) to interrupt...."
while [ -f /tmp/my_tmp_file_$$ ]; do
echo File exists
sleep 1
done
echo We never get here
exit 0
########################## |
|