chap 2 about trap INT
there is something wrong with "trap INT"
the code is :
##############´úÃëÃçÃã¬the red is wrong###############
#!/bin/sh
trap 'rm -f /tmp/my_tmp_file_$$' INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_tmp_file_$$
echo "Press interrupt (Ctrl-C) to interrupt...."
while [ -f /tmp/my_tmp_file_$$ ]; do
echo File exists
sleep 1
done
echo The file no longer exists
trap INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_tmp_file_$$
echo "Press 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
##########################
i change "trap INT" to "trap 2" and it right.why???
###########the answers#############
# ./_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 ...]
##############################
ÃÃÃÿ´beginning linux programmingk( linux³ÃÃòÃè¼ÃµÃÃý°æ£©
ÃéÃõöþÃà shell±à ³à ÃÃû¸ö´úÃ룬ôÃóö´Ã¡£
ôÃýá¹ûÃçÃãº
°Ã´úÃëÃá°trap INT¡±¸Ãê¡°trap 2¡±¼´¿ÃÃÃôÃã¬Ãë½ÃÃâÃÃÃªà ²Ã´£¿
´úÃëÃçÃãº
###########ôÃýá¹û#############
# ./_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 "Press interrupt (Ctrl-C) to interrupt...."
while [ -f /tmp/my_tmp_file_$$ ]; do
echo File exists
sleep 1
done
echo The file no longer exists
trap INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_tmp_file_$$
echo "Press 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
##########################
|