Shell脚本弹奏中文版“生日快乐歌”

在《Shell命令控制蜂鸣器发声》一文中,我们了解到了如何在Ubuntu下安装beep命令来控制PC主板上蜂鸣器发声,这次我们想让蜂鸣器弹奏出中文版的“生日快乐歌”,首先还是要用sudo modprobe pcspkr命令加载驱动,然后在Shell脚本所在目录下执行bash -e beep_birthday_song.sh命令,这样就可以执行我们写的脚本弹奏了,我们的脚本名字为beep_birthday_song.sh,内容如下:
#!/bin/sh

freq=(392 392 440 392 523 494 392 392 440 392 587 523 392 392 784 659 523 494 440 698 698 659 523 587 523)
delay=(375 125 500 500 500 1000 375 125 500 500 500 1000 375 125 500 500 500 500 1000 375 125 500 500 500 1000)

i=0
len=${#freq[*]}
while [ $i -lt $len ]
do
        beep -f ${freq[$i]} -l ${delay[$i]}
        let ++i
done
参考网址:
http://jpuyy.com/2012/11/linux-beep.html http://stackoverflow.com/questions/12919378/solvedplaying-beep-in-c-linux http://kirrus.co.uk/2010/09/linux-beep-music/ http://snipplr.com/view/62662/jingle-bells-song/ http://wiki.mikrotik.com/wiki/Super_Mario_Theme http://frank-buss.de/beep/index.html http://stackoverflow.com/questions/7247279/bash-set-e-and-i-0let-i-do-not-agree http://zhenshi4597.blog.51cto.com/1891465/871166 http://blog.csdn.net/yy_done/article/details/7242309 http://www.coder4.com/archives/3853

评论

此博客中的热门博文

I/O映射之I/O端口

通过Netlink检测网线插拔

使用seq_file