shell脚本学习笔记(二)myplayer添加播放列表的源码
shell脚本学习笔记(二)
#!/bin/sh
#MList
#############################function sets#################################
#to add a new item to the list,if the list is not exit,then creat it
add()
{
Hold="" #for hold something
SName="" #name for the song
Lines="0"
NextLine=""
Hold=`find $MusicPath -name ListLib`
if [ -z $Hold ];then #if the hold is empty
touch $MusicPath/ListLib
fi
while :
do
echo "Enter the num of the song you want to add"
echo "[q to quit][li to see the list]:"
read SNum
if [ -n $SNum ];then
if [ $SNum = "q" ];then
return 0
fi
if [ $SNum = "li" ];then
ls $MusicPath|sed =
echo "****************************************************"
echo "Enter the number of the song"
read SNum
fi
#get the lines number of the list
SNum=`expr $SNum /* 2`
SName=`ls $MusicPath|sed =|sed -n /`echo $SNum/`p`
Lines=`wc -l $MusicPath/ListLib|awk '{print $1}'`
NextLine=`expr $Lines + 1`
echo "$NextLine $MusicPath/$SName">>$MusicPath/ListLib
else
echo "You entered anything!Enter again!"
fi
done
return 0
}
#delete some items in the list
delete()
{
Hold="" #for hold something
SName="" #name for the song
Lines="0"
NextLine=""
MaxLines=""
Hold=`find $MusicPath -name ListLib`
if [ -z $Hold ];then #if the hold is empty
echo "Still No list ,enter add to creat one!"
return 0
fi
while :
do
Lines=`wc -l $MusicPath/ListLib|awk '{print $1}'`
if [ $Lines -eq "0" ]; then
echo "List empty!"
return 0
fi
echo "Enter the name of the song you want to delet[q to quit]:"
echo -e "Or enter /"l/" to check the list"
read SName
if [ -n $SName ];then
if [ $SName = "q" ];then
break
fi
if [ $SName = "l" -o $SName = "L" ];then
cat $MusicPath/ListLib|more #open the list
echo "you can enter the number of the song:"
read Lines
else
#get the lines which will be delet
Lines=`sed -n /`echo $SName/`p $MusicPath/ListLib|awk '{print $1}'`
fi
#delet the item choosed
sed `echo $Lines`d $MusicPath/ListLib>c;mv c $MusicPath/ListLib
#every lines bellow the $Lines minutes 1
MaxLines=`wc -l $MusicPath/ListLib|awk '{print $1}'`
while [ $Lines -le $MaxLines ]
do
NextLine=$Lines
Lines=`expr $Lines + 1`
sed s/$Lines/$NextLine/ $MusicPath/ListLib>out
mv out $MusicPath/ListLib
done
else
echo "You entered anything!Enter again!"
fi
done
return 0
}
#play in loop
loopPlay()
{
echo "loop running....[ctrl]+z to stop!"
while :
do
mplayer `cat $MusicPath/ListLib|awk '{print $2}'`
done
return 0
}
#play in random
randomPlay()
{
count="0"
i="0"
Hold=`wc -l $MusicPath/ListLib|awk '{print $1}'`
#when the list is less than 5 items
Random=`awk 'BEGIN{srand();print a=int(10*rand())}'`
if [ $Hold -le "10" ];then
while :
do
if [ $Random -le $Hold ];then
Play=`sed -n /`echo $Random/`p $MusicPath/ListLib|awk '{print $2}'`
echo "&&&&&&&&&&&$Play ^^^^^^^^^^^^^^^^^^^^"
mplayer $MusicPath/$Play
fi
Random=`awk 'BEGIN{print a=int(10*rand())}'`
done
#when the list is more than 5 items
else
while : #play untill you entered the [esc] button
do
Random=`expr $Random + $count`
i=`expr $Hold - $count`
if [ $i -ge "5" ];then
count=`expr $count + 5`
else
count="0"
fi
#when the random is more than total items,do nothing
#if less than items,play the music
if [ $Random -le $Hold ];then
Play=`sed -n /`echo $Random/`p $MusicPath/ListLib|awk '{print $2}'`
echo "&&&&&&&&&&&$Play ^^^^^^^^^^^^^^^^^^^^"
mplayer $Play
fi
Random=`awk 'BEGIN{print a=int(10*rand())}'`
done
fi
return 0
}
#select a song to play
selectPlay()
{
Num=""
Hold=""
Play=""
echo "###############################################################"
echo "The items are as following:"
cat `echo $MusicPath`/ListLib|more
echo "###############################################################"
echo "Enter the items' number to select"
read Num
Hold=`wc -l $MusicPath/ListLib|awk '{print $1}'`
if [ $Hold -ge $Num ];then
Play=`sed -n /`echo $Num/`p $MusicPath/ListLib|awk '{print $2}'`
mplayer $Play
else
echo "No such files!"
fi
}
#############################################################################
MusicPath=/home/flora/Music #where the music is stored
export MusicPath
PWDPath=`pwd` #show the current path
Hold="" #for hold something
choice="" #hold for user's choose
#see in the .bashrc if it has the right path
#if no then add the new path
Hold=`grep "PATH" "$HOME/.bashrc"|grep $PWDPath`
echo "#######$Hold#######"
if [ -z $Hold ];then #if the hold is empty
#add a new path to the $PATH
echo -e "PATH=$PATH:$PWDPath /n export PATH">>$HOME/.bashrc
source $HOME/.bashrc #make the chtoange valued
fi
echo "MList---ad|de|lo|ra|se|list|lab|q"
echo "ad --add new item to the play list"
echo "de --delete one or more items in the play list"
echo "lo --play the music in the list in loop style"
echo "ra --play the music in the list in random style"
echo "se --play the music by select one item"
echo "list --to see in the music list"
echo "lib --to see in the music library"
echo "q --quit"
read choice
while [ $choice!="q" ]
do
case $choice in
ad|Ad)
add
;;
de|De)
delete
;;
lo|Lo)
loopPlay
;;
ra|Ra)
randomPlay
;;
se|Se)
selectPlay
;;
list|List)
cat $MusicPath/ListLib|more
;;
lab|Lab)
ls $MusicPath|more
;;
q|Q)
exit 0
;;
*)
echo "Illegel input enter again!"
;;
esac
echo "MList---ad|de|lo|ra|se|list|lab|q"
read choice
done
shell脚本学习笔记(二)myplayer添加播放列表的源码相关推荐
- Mr.J-- jQuery学习笔记(二十四)--剖析jQuery源码--extend
定义和用法 jQuery.extend() 函数用于将一个或多个对象的内容合并到目标对象. 注意:1. 如果只为$.extend()指定了一个参数,则意味着参数target被省略.此时,target就 ...
- linux读取环境变量替换,linux Shell脚本学习笔记二(变量和环境变量)
2.变量和环境变量 使用env命令在终端中查看所有与此终端进程相关的环境变量.对于每个进程,在起运行时的环境变量可以使用下面的命令来查看: cat /proc/$PID/environ 其中,将PID ...
- Shell脚本学习-阶段二
文章目录-Shell脚本学习阶段二 前言 shell脚本实操2 1.获取随机字符串或数字 2.定义一个颜色输出字符串函数 3.批量创建用户 4.检查软件包是否安装 5.检查服务状态 6.检查主机存活状 ...
- glibc-2.23学习笔记(一)—— malloc部分源码分析
glibc-2.23学习笔记(一)-- malloc部分源码分析 搭建Glibc源码调试环境 1.下载并解压glibc源码 2.配置gdb 3.编译测试程序 第一次调用 源码分析 __libc_mal ...
- activiti学习(二十一)——流程虚拟机源码分析(三)——从进入到离开userTask
前言 承接上文<activiti学习(二十)--流程虚拟机源码分析(二)--从开始节点离开到下个节点前>,假设execution接下来进入的节点是userTask,本文分析一下进入user ...
- shell脚本学习笔记一
又开始写学习笔记了,呵呵... 今年打算选择一门技术系统的学习一下.编程语言.虚拟机技术.数据库.大数据.云计算在这些种类中,我选择了shell编程.为什么选择shell呢?也没有什么具体的原因.以前 ...
- Shell脚本(学习笔记1)
shell脚本学习记录 为什么学习shell脚本? 在一些复杂的linux维护工作过程中,大量的重复性的输入和交互操作不但费时费力,而且容易出现错误:然而编写shell脚本程序,可以批量处理.自动化的 ...
- shell 脚本学习笔记
shell 脚本学习总结: 文件表达式 -e filename 如果 filename存在,则为真 -s file exists and has a size greater than zero. 判 ...
- Shell脚本学习-阶段二十七-命令解释三
文章目录 前言 quyotastats repquota convertquota swapoff swapon sync chroot getent last lastb lastlog logro ...
- shell脚本——学习笔记(包含应用案例)
题头为本人编写shell脚本格式^v^ #!/bin/bash #**************** #Author: Pakho #Date: 2021-00-00 #FileName: .sh #* ...
最新文章
- iscroll 滚动刷新
- HIVE 查询显示列名 及 行转列显示
- 在已有SQL 2005 Server 群集中添加节点
- HDU3662(求三维凸包表面的多边形个数,表面三角形个数,体积,表面积,凸包重心,凸包中点到面的距离)
- Flask爱家租房--发布新房源(保存房屋图片)
- ValueError: Program dot not found in path.python下运行pygraphviz出现报错
- linux编程学习_您需要编程技能才能学习Linux吗?
- c语言数据驱动编程,如何学习智能手机驱动编程
- java 新闻编辑_使用 Java 构建你自己的文本编辑器|Linux 中国
- SteamAchievementManager刷steam游戏成就新手教程
- pandas报错:columns overlap but no suffix specified
- 【商业模式学习感悟】趣步App——新型商业模式,还是新型传销?
- 周文上海大学计算机学院,上海大学计算机工程与科学学院硕士生导师周文
- Win10官网原版安装
- C语言变量的存储类别和生存期
- H5调用移动端手机摄像头
- socat的安装与使用
- 一元二次不等式和一元三次不等式解法的思考
- 《算法竞赛进阶指南》0x6B T2 升降梯上
- Python爬取CCTV15
热门文章
- 以太网帧分析与IP报文结构分析(二)
- AutoCAD-图纸集使用方法
- 吴琦:没有被“双非学历”困住的边界突破者
- 南京邮电大学电子电路课程设计可编程音乐自动演奏电路
- 三星note10 android q,【极光ROM】-【三星NOTE10/NOTE10+/5G N97XX-855】-【V6.0 Android-Q-TE1】...
- Drools(2):Drools快速入门
- 旭荣管理软件怎么修改小票内容_水果门店管理系统怎么管理水果门店的
- 插桩 java_“插桩”式技术
- 「标签管理」用数据管理思维去管理你的日常电子化资料、文件、笔记等
- 计算机遥感毕设选题,遥感硕士毕业论文题目