LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash script debugging issue (https://www.linuxquestions.org/questions/programming-9/bash-script-debugging-issue-616862/)

internetSurfer 01-28-2008 09:01 AM

Bash script debugging issue
 
I am having difficulties debugging this bash
script for setting EQ presets in MPlayer. (Script Source)

In Geany I have used set -x to see output.

Currently working on getting bashdb installed. :study:

Any feedback or help appreciated.

Code:

+ equalizer=( 0 0 0 0 0 0 0 0 0 0 )
+ equalizer_default=( 0 0 0 0 0 0 0 0 0 0 )
+ CLASSICAL=( 0 0 0 0 0 0 -2.5 -2.5 -2.5 -3.4 )
+ CLUB=( 0 0 2.8 2.0 2.0 2.0 1.1 0 0 0 )
+ DANCE=( 3.4 2.5 .8 0 0 -2.0 -2.5 -2.5 0 0 )
+ FULL_BASS=( -2.8 3.4 3.4 2.0 .5 -1.4 -2.8 -3.7 -4.0 -4.0 )
+ FULL_BASS_TREBLE=( 2.5 2.0 0 -2.5 -1.7 .5 2.8 4.0 4.2 4.2 )
+ FULL_TREBLE=( -3.4 -3.4 -3.4 -1.4 .8 4.0 4.2 4.2 4.2 4.2 )
+ LAPTOP_SPEAKERS_HEADPHONES=( 1.7 4.0 2.0 -1.1 -.8 .5 1.7 3.4 4.2 4.2 )
+ LARGE_HALL=( 3.7 3.7 2.0 2.0 0 -1.7 -1.7 -1.7 0 0 )
+ LIVE=( -1.7 0 1.4 2.0 2.0 2.0 1.4 .8 .8 .8 )
+ PARTY=( 2.5 2.5 0 0 0 0 0 0 2.5 2.5 )
+ POP=( -.5 1.7 2.5 2.8 2.0 0 -.8 -.8 -.5 -.5 )
+ REGGAE=( 0 0 0 -2.0 0 2.2 2.2 0 0 0 )
+ ROCK=( 2.8 1.7 -2.0 -2.8 -1.1 1.4 3.1 4.0 4.0 4.0 )
+ SKA=( -.8 -1.7 -1.4 0 1.4 2.0 3.1 3.4 4.0 3.4 )
+ SOFT=( 1.7 .5 0 -.8 0 1.4 2.8 3.4 4.0 4.2 )
+ SOFT_ROCK=( 1.4 1.4 .8 0 -1.4 -2.0 -1.1 0 .8 3.1 )
+ TECHNO=( 2.8 2.0 0 -2.0 -1.7 0 2.8 3.4 3.4 3.1 )
+ max_depth=1
+ for i in '"$@"'
+ case "$i" in
+ myfile=mktemp
./presets: line 119: syntax error near unexpected token 'done'

Code:

#!/bin/bash
set -x

equalizer=( 0 0 0 0 0 0 0 0 0 0 )
equalizer_default=( 0 0 0 0 0 0 0 0 0 0 )

CLASSICAL=( 0 0 0 0 0 0 -2.5 -2.5 -2.5 -3.4 )
CLUB=( 0 0 2.8 2.0 2.0 2.0 1.1 0 0 0 )
DANCE=( 3.4 2.5 .8 0 0 -2.0 -2.5 -2.5 0 0 )
FULL_BASS=( -2.8 3.4 3.4 2.0 .5 -1.4 -2.8 -3.7 -4.0 -4.0 )
FULL_BASS_TREBLE=( 2.5 2.0 0 -2.5 -1.7 .5 2.8 4.0 4.2 4.2 )
FULL_TREBLE=( -3.4 -3.4 -3.4 -1.4 .8 4.0 4.2 4.2 4.2 4.2 )
LAPTOP_SPEAKERS_HEADPHONES=( 1.7 4.0 2.0 -1.1 -.8 .5 1.7 3.4 4.2 4.2 )
LARGE_HALL=( 3.7 3.7 2.0 2.0 0 -1.7 -1.7 -1.7 0 0 )
LIVE=( -1.7 0 1.4 2.0 2.0 2.0 1.4 .8 .8 .8 )
PARTY=( 2.5 2.5 0 0 0 0 0 0 2.5 2.5 )
POP=( -.5 1.7 2.5 2.8 2.0 0 -.8 -.8 -.5 -.5 )
REGGAE=( 0 0 0 -2.0 0 2.2 2.2 0 0 0 )
ROCK=( 2.8 1.7 -2.0 -2.8 -1.1 1.4 3.1 4.0 4.0 4.0 )
SKA=( -.8 -1.7 -1.4 0 1.4 2.0 3.1 3.4 4.0 3.4 )
SOFT=( 1.7 .5 0 -.8 0 1.4 2.8 3.4 4.0 4.2 )
SOFT_ROCK=( 1.4 1.4 .8 0 -1.4 -2.0 -1.1 0 .8 3.1 )
TECHNO=( 2.8 2.0 0 -2.0 -1.7 0 2.8 3.4 3.4 3.1 )

#————————————————–
# for i in ${CLASSICAL[@]:0} ; do
# output=`echo "scale=1 ; $i/2.8" | bc -l`
# echo -n “$output ”
# done
#————————————————–

strlen(){
return 'echo -n "$1" | wc -m'
}

likeit(){
clear
echo -e “\e[31me\e[m - equalizer
\e[31mq\e[m - quit
\e[31mr\e[m - remove song”
read -n 1 quest
case $quest in
q)
echo
exit 1 ;;
r)
rm -f "$1"
;;
e)
return 1 ;;
esac
return 0
}

select_equalizer(){
local output='widtools -menu -label 'Equalizer Preset:' \
Classical Club Dance Full_Bass Full_Bass_Treble Full_Treble Laptop_Speakers_Headphones Large_Hall Live Party Pop Reggae Rock Ska Soft Soft_rock Techno 'NEVERMIND!!!'\
-fn tiny normal -back black -fore white'

case "$output" in
1) equalizer=( ${CLASSICAL[*]} ) ;;
2) equalizer=( ${CLUB[*]} ) ;;
3) equalizer=( ${DANCE[*]} ) ;;
4) equalizer=( ${FULL_BASS[*]} ) ;;
5) equalizer=( ${FULL_BASS_TREBLE[*]} ) ;;
6) equalizer=( ${FULL_TREBLE[*]} ) ;;
7) equalizer=( ${LAPTOP_SPEAKERS_HEADPHONES[*]} ) ;;
8) equalizer=( ${LARGE_HALL[*]} ) ;;
9) equalizer=( ${LIVE[*]} ) ;;
10) equalizer=( ${PARTY[*]} ) ;;
11) equalizer=( ${POP[*]} ) ;;
12) equalizer=( ${REGGAE[*]} ) ;;
13) equalizer=( ${ROCK[*]} ) ;;
14) equalizer=( ${SKA[*]} ) ;;
15) equalizer=( ${SOFT[*]} ) ;;
16) equalizer=( ${SOFT_ROCK[*]} ) ;;
17) equalizer=( ${TECHNO[*]} ) ;;
*) return 1 ;;
esac
return 0
}

equalizer2mplayer(){
equalizer_args=
local separator=':'
for i in "${equalizer[@]}" ; do
strlen "$equalizer_args"
[ $? -gt 0 ] && equalizer_args="${equalizer_args}${separator}"
equalizer_args="${equalizer_args}${i}"
done
equalizer_args="equalizer=$equalizer_args"
}

reset_equalizer(){
equalizer=( ${equalizer_default[*]} )
}

max_depth=1

for i ; do
case "$i" in
-g|–global|-global)
max_depth=9
;;
esac
done

myfile='mktemp'
{
while read l $myfile

equalizer2mplayer

while read f /dev/null 2>&1
if [ $? -ne 0 ] ; then
likeit "$f"
[ $? -eq 1 ] &fi
break
done

reset_equalizer
equalizer2mplayer
done 9
}


druuna 01-28-2008 09:08 AM

Hi,

After myfile='mktemp' there's a {, but no function is declared.

Should this block be a function?

Hope this helps.

jlinkels 01-28-2008 12:39 PM

There are a bunch of errors:

Code:

myfile='mktemp'
{

This is at least suspicious, I ma not sure whether stray '{}' are allowed in bash

Code:

while read l $myfile

equalizer2mplayer

No 'do' after while

Code:

while read f /dev/null 2>&1
No 'do' after while

Code:

if [ $? -ne 0 ] ; then
likeit "$f"
[ $? -eq 1 ] &fi
break
done

Test not preceeded by 'if'
'if' without 'fi' (or I don't understand the meaning of &fi, but I have never seen it before, and if it is possible to do such things, it is obfuscated code at best and I don't see any reason to use that here)

There might be more errors, but I am only a human being, not a script interpreter. Have also a look at the docs, see my signature.

It is easier to read if you indent your code.

jlinkels

internetSurfer 01-28-2008 07:19 PM

Thanks for the feedback.
I will take a look @ the recommended suggestions.

Also why would someone post a script that doesn't work. :confused:

_

jlinkels 01-28-2008 08:24 PM

Quote:

Originally Posted by internetSurfer (Post 3038237)
Also why would someone post a script that doesn't work. :confused:

You just did :D

Seriously though, probably the user had posted inadvertently an old version of his script.

jlinkels


All times are GMT -5. The time now is 04:46 PM.