LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] bash bug?

[ILUG] bash bug?

Brian Foster blf at utvinternet.ie
Fri Jun 14 15:44:32 IST 2002


  | Date: Fri, 14 Jun 2002 12:12:14 +0100
  | From: Stephen Shirley <diamond at skynet.ie>
  |
  | [ ... The bash script is ] supposed to allow ctrl-c to be pressed during
  | the sleep_60 function, which should just return, and all it well.
  | However, it only works the first time.  The next time sleep_60 is called
  | [ the trap does not appear to be taken ... ].
  | 
  | So, can anyone see any problems [ ... ] or is it actually a bash bug (or
  | even something else)?

 interesting.  at first glance, and sans googling, it does
 sort of look like a bash(1) problem ....

 fix (work-around) is trivial (tested with bash 2.05.0(1)
 on SuSE 7.3; but may _not_ work other Bourne-ish shells,
 due to various syntax issues such as the `local' builtin
 and `return -1'):

=====(cut here and below)=====(working variant of original)=====(bash script)=====
#!/bin/bash

function sleep_60 {
    local i=60
    trap 'i=-1' INT
    echo -n "Died ... restarting in "
    while [ $i -gt 0 ]; do
        echo -n "$i"
        i=$((i-1))
        sleep 1
        echo -n ' '
    done
    echo NOW
	# unlike ksh(1), bash(1) traps are global, so be sure to clean up in
	# _all_ cases (i.e., whether or not the trap is taken) --- otherwise
	# there will be a lurking reassignment of `i' on any subsequent INT
	# (almost certainly not what is wanted!) ...
	#
	# N.b. following resets the INT handler to the original value when
	#      the script started, which is not always what's wanted  ;-(
	#
    trap - INT
    return $i
}

while true; do
    #... do stuff
    sleep_60
done
=====(cut here and above)=====(working variant of original)=====(bash script)=====

 the comment within the above work-around also points out
 a problem in the original script --- it left the `return'
 handler active for any SIGINT (e.g., ctrl-C) subsequent to
 the first invocation of sleep_60, which is very unlikely
 to be desired!

cheers,
	-blf-
--
 Innovative, very experienced, Unix and      | Brian Foster    Dublin, Ireland
 Chorus (embedded RTOS) kernel internals     | e-mail: blf at utvinternet.ie
 expert looking for a new position ...       | mobile: (+353 or 0)86 854 9268
  For a résumé, contact me, or see my website  http://www.blf.utvinternet.ie

    Stop E$$o (ExxonMobile):  «Whatever you do, don't buy Esso --- they
     don't give a damn about global warming.»    http://www.stopesso.com
     Supported by Greenpeace, Friends of the Earth, and numerous others...




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell