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”`
bash, programming, cli, linux, overflow