Linux, programming, computers and life

November 8, 2008

overflow in shell script

Filed under: CLI, programming, linux

Overflow in shell script… while it sounds strange, it actually happened to me :) . I have a script which does recoding of mp3 files in order to reduce bitrate and space those files take. I tried to be smart and first detect the bitrate in order to avoid redundant recoding. Well, my script actually worked for a long time, but then it refused to recode file with bitrate 256 ;) .
It was my fault of course. In order to determine the bitrate, i used the following ash function:
# function to determine bitrate:
# expects a file as parameter
determine_birate() {
    if [ -z “$1″ ]
    then
        return 0 # invalid
    fi
   
    if [[ “${MP3INFO}” == “” ]]
    then
        return 1 # invalid
    fi

    return `”${MP3INFO}” -p “%r” “$1″`
}

MP3INFO is an application i use in order to read mp3 files meta data. Well, when the bitrate was 256 i got 0 returned, i guess bash has some limit of 1 byte somewhere :) . My quick fix was (and now it works great):
# function to determine bitrate:
# expects a file as parameter
determine_birate() {
    if [ -z “$1″ ]
    then
        return 0 # invalid
    fi
   
    if [[ “${MP3INFO}” == “” ]]
    then
        return 1 # invalid
    fi

    echo `”${MP3INFO}” -p “%r” “$1″`
}
….
CURRENT_BITRATE=`determine_birate “$file”`

, , , ,

Comments »

The URI to TrackBack this entry is: http://linux4all.blogsome.com/2008/11/08/overflow-in-shell-script/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers