|
From: | tytus64 |
Subject: | bizarre trap behavior while reading a file |
Date: | Fri, 25 Mar 2011 14:25:35 -0700 (PDT) |
I started execution of the following script and and repeatedly sent a SIGHUP to it from another shell. If SIGHUP is received within the first while loop the loop terminates with "wc -l" printing fewer than 4158 lines. If SIGHUP is received within the second while loop the loop still continues and the second "wc -l" prints always 4158 lines. I am really curious why is this happening!!! This is obviously a test scrip. I spent quite a long time debugging my work script to get to this point ;). #!/bin/bash log_file=<file with 4158 lines> line_num=0 trap "sig_received=true" HUP rm out.log cat $log_file | { while read line do line_num=`expr $line_num + 1` echo $line_num: $line >> ./out.log done } wc -l out.log rm out.log line_num=0 while read line do line_num=`expr $line_num + 1` echo $line_num: $line >> ./out.log done < $log_file wc -l out.log exit 0 -- View this message in context: http://old.nabble.com/bizarre-trap-behavior-while-reading-a-file-tp31242064p31242064.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
[Prev in Thread] | Current Thread | [Next in Thread] |