0

I am making a bash script. the objective is: execute a program wait some seconds reset the program and repeat the process. I make 2 scripts but i don't know where is the error...

 #!/bin/bash
while true; 
do 
seg=`date +%M`;
if [[ "$seg" -eq "30" ]]; 
then killall sox;
echo "reset"; 
fi
done

bash: error sintáctico cerca del elemento inesperado `;'

#!/bin/bash
while true;
do
nice -n-10 sox -q -V0 --multi-threaded -t alsa hw:2,0 -t alsa pcm.default && 
done

bash: error sintáctico cerca del elemento inesperado `done'

2
  • What's the intention of the second script? Start a new sox process if the old one dies? Just lose the && then. Commented Nov 23, 2012 at 7:54
  • Many of us here have no idea what "sintáctico cerca del elemento inesperado" means... Don't make us guess... Commented Apr 22, 2014 at 17:00

1 Answer 1

1

Issues with Script #1:

The ; notation is to run multiple commands on the same line, one after another. Bash syntax requires that while and do on separate lines (same with if ... and then, and separated by ; if on the same line. Command statements are not normally terminated with a ; char in bash.

Change your code from:

#!/bin/bash
while true; 
do 
seg=`date +%M`;
if [[ "$seg" -eq "30" ]]; 
then killall sox;
echo "reset"; 
fi
done

To:

#!/bin/bash
while true
do 
    seg=`date +%M`
    if [[ "$seg" -eq "30" ]]; then
        killall sox
        echo "reset"
    fi
done

Issues with Script #2:

& means to run the command as a background process. && is used for conditional command chaining, as in: "If the previous command before && succeeds, then run the next command after the &&"

Change from:

#!/bin/bash
while true;
do
nice -n-10 sox -q -V0 --multi-threaded -t alsa hw:2,0 -t alsa pcm.default && 
done

To:

#!/bin/bash
while true
do
    nice -n-10 sox -q -V0 --multi-threaded -t alsa hw:2,0 -t alsa pcm.default &
done
Sign up to request clarification or add additional context in comments.

3 Comments

thanks. there are no syntax error on second script but is not working properly.
you probably wanted &, not &&
Actually, you probably don't want &. That would flood the system with background sox processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.