LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-28-2008, 09:01 AM   #1
internetSurfer
Member
 
Registered: Jan 2008
Location: w3c
Distribution: Slackware 12 Zenwalk 5.2
Posts: 71

Rep: Reputation: 16
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.

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 
}

Last edited by internetSurfer; 01-28-2008 at 09:05 AM.
 
Old 01-28-2008, 09:08 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

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

Should this block be a function?

Hope this helps.
 
Old 01-28-2008, 12:39 PM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,163

Rep: Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506
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
 
Old 01-28-2008, 07:19 PM   #4
internetSurfer
Member
 
Registered: Jan 2008
Location: w3c
Distribution: Slackware 12 Zenwalk 5.2
Posts: 71

Original Poster
Rep: Reputation: 16
Thanks for the feedback.
I will take a look @ the recommended suggestions.

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

_
 
Old 01-28-2008, 08:24 PM   #5
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,163

Rep: Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506
Quote:
Originally Posted by internetSurfer View Post
Also why would someone post a script that doesn't work.
You just did

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

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] having trouble debugging this bash script. jons Programming 4 02-08-2007 06:51 AM
[SOLVED] issue with variable in bash script angel115 Programming 4 08-21-2006 01:42 PM
Debugging a Bash Shell Script solarblast Linux - General 1 02-23-2006 01:44 AM
small bash script issue zoomzoom Linux - General 7 06-08-2004 06:33 PM
BASH - simple script issue - syntax? tw1ggy5 Programming 11 05-21-2004 09:09 AM


All times are GMT -5. The time now is 11:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration