shell script bug [was: capturing CBC Radio from an internet stream]

Chris F.A. Johnson cfaj-uVmiyxGBW52XDw4h08c5KA at public.gmane.org
Mon Apr 7 20:26:23 UTC 2008


On Mon, 7 Apr 2008, D. Hugh Redelmeier wrote:

> | Date: Sun, 17 Feb 2008 02:09:21 -0500 (EST)
> | From: D. Hugh Redelmeier <hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org>
>
> | Here's a shell script that I call GRAB1hrCBC1mms:
>
> |     DATE=`date +%Y.%m.%d-%H.%M`
> |
> |     mmsrip --delay=3600 --output=$DATE.wma mms://wm.cbc.ca/cbcr1-${CITY:-toronto}
>
> I "improved" this, allowing the recording time to be overridden and a
> description to be added to the resulting file's name:
>    mmsrip --delay=${SECONDS:-3600} --output=${DATE}${DESCRIPTION:-}.wma \
> 	mms://wm.cbc.ca/cbcr1-${CITY:-toronto}
>
> Simple and useful, eh?
>
> Well, the result was that my partition slowly filled up and the
> recording never terminated.  The first time, I thought it was a fluke.
>
> It turns out that bash "owns" the variable SECONDS.  It is the number
> of seconds since the shell was invoked.  mmsrip was probably seeing
> --delay=0.
>
> I hate reserved words.  I hate silently reserved words -- no warning
> just bad behaviour.
>
> The fix is simple.  I used DURATION instead.

    A simpler fix is to avoid using upper case for variable names. All
    bash's shell variables (with the exception of auto_resume and
    histchars) are upper case.

-- 
    Chris F.A. Johnson, webmaster         <http://woodbine-gerrard.com>
    ========= Do not reply to the From: address; use Reply-To: ========
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list