我正在写一个bash脚本。目标是:执行一个程序,等待几秒钟,重置程序,然后重复这个过程。我写了两个脚本,但我不知道哪里出了错…
#!/bin/bash
while true;
do
seg=`date +%M`;
if [[ "$seg" -eq "30" ]];
then killall sox;
echo "reset";
fi
donebash: 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 &&
donebash: error sintáctico cerca del elemento inesperado‘`done’
发布于 2012-11-23 08:32:08
脚本#1的问题:
;表示法是在同一行上一个接一个地运行多个命令。Bash语法要求while和do在不同的行上(与if ...和then相同,如果在同一行上,则用;分隔。在bash中,命令语句通常不会以;字符结尾。
将您的代码更改为:
#!/bin/bash
while true;
do
seg=`date +%M`;
if [[ "$seg" -eq "30" ]];
then killall sox;
echo "reset";
fi
done至:
#!/bin/bash
while true
do
seg=`date +%M`
if [[ "$seg" -eq "30" ]]; then
killall sox
echo "reset"
fi
done脚本#2的问题:
&表示将命令作为后台进程运行。&&用于条件命令链接,如:“如果&&之前的前一条命令成功,则运行&&后的下一条命令”
更改自:
#!/bin/bash
while true;
do
nice -n-10 sox -q -V0 --multi-threaded -t alsa hw:2,0 -t alsa pcm.default &&
done至:
#!/bin/bash
while true
do
nice -n-10 sox -q -V0 --multi-threaded -t alsa hw:2,0 -t alsa pcm.default &
donehttps://stackoverflow.com/questions/13521723
复制相似问题