Reputation: 2098
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'
Upvotes: 0
Views: 1121
Reputation: 47269
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
Upvotes: 1