# Based on alarm script (http://www.linuxcommand.org/html_text/alarm.html)
# and startrec.sh script (http://sox.sf.net/examples/startrec.sh).
# License GPL. 
(while true; do
    rec -c1 -r 8000 -C 3 -q ./`date +%F#%T`.wav silence 1 5 7.5% 0:3 0:4 7.5%
done ) &
# Get process ID of sub-subshell
pid=$!
# Display prompt and wait for user to press enter key
echo
echo
echo
echo "Recording. To stop the process press 'Enter'"
echo
echo
read foo
# Now that key has been pressed, kill sub-shell
kill -9 $pid
killall rec
# All done - make pid empty so clean_up won't kill anything
pid=
normalize -a -3dB  ./*.wav
