Shell脚本同时运行多个循环

时间:2013-12-03 18:36:01

标签: shell loops

#!/bin/bash

# Define the infos
Clock() {
        DATE=$(date "+%a %b %d, %T")

        echo -n " $DATE"
}

Sound() {
    Level=$(awk -F"[][]" '/dB/ { print $2 }' <(amixer sget Master))

    echo -n " $Level"
}

# Print the info


while true
do
    echo "\c\f0 $(Clock)\ur"
    sleep 1
done &

while true
    echo "\r\f0 $(Sound)\ur"
done

我需要同时运行这两个循环。我用Google搜索并发现添加“&amp;”在第一个结束时应该在背景上运行它。但是,当我尝试它时给出了错误:

/home/yves/.fluxbox/bar.sh: line 27: syntax error near unexpected token `done'
/home/yves/.fluxbox/bar.sh: line 27: `done'

任何帮助表示赞赏!这会很容易用另一种语言吗?

1 个答案:

答案 0 :(得分:1)

问题出现在你的第二个while循环中:你没有do,因此你永远不会关闭条件块并启动正文块。

那是 - 改变这个:

while true
    echo "\r\f0 $(Sound)\ur"
done

到此:

while true ; do
    echo "\r\f0 $(Sound)\ur"
done
相关问题