Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK Beginning Linux Programming, 3rd Edition
This is the forum to discuss the Wrox book Beginning Linux Programming, 2nd Edition by Richard Stones, Neil Matthew, Alan Cox; ISBN: 9780764543739
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK Beginning Linux Programming, 3rd Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 13th, 2008, 01:02 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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



##########################





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help to trap errors starnet SQL Server 2000 1 October 6th, 2006 11:05 AM
GetObject Trap bostek VBScript 2 November 24th, 2004 02:39 AM
Disable/Trap msgBox?? adelgado Access VBA 1 September 13th, 2004 03:54 PM
How can I trap for a connection error cdukes77@bellsouth.net Classic ASP Databases 1 April 27th, 2004 03:09 AM
Trap for empty recordset in a SP Mitch Access VBA 2 September 5th, 2003 04:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.