很好理解,键入内容为回车的时候,内容肯定为null,再次 加上if 判断,内容为空就给赋值为默认值。
在此需要掌握if相关逻辑表达式
if [ -z “$null” ]
-z $null为null,即为真
-n $null不为null,即为真
以下将以实际代码的形式展示
#!/bin/bash
#panda_jimmy
#181204
read -p "Pls input the url(http://cncwo.cdn.cibn.cc/m3u8/4a39dc7ab2dbe801ddc94a8bdedc3656.m3u8):" url
if [ -z "$url" ];then
url="http://cncwo.cdn.cibn.cc/m3u8/4a39dc7ab2dbe801ddc94a8bdedc3656.m3u8"
fi
read -p "Pls input the key(Hzx6iAj5lUfoEUwGHUl9s5YXSQCk1DOjpQX6XZ6tZq4jCNCWOO4FoLLTN0CI0ABn9RanSqsPHhmpEI0GEDIfFQzxnMNikKZcOYUZ):" key
if [ -z "$key" ];then
key="Hzx6iAj5lUfoEUwGHUl9s5YXSQCk1DOjpQX6XZ6tZq4jCNCWOO4FoLLTN0CI0ABn9RanSqsPHhmpEI0GEDIfFQzxnMNikKZcOYUZ"
fi
read -p "Pls input the ttl(86400):" ttl
if [ -z "$ttl" ];then
ttl="86400"
fi
read -p "Pls input the channel(cncwo):" channel
if [ -z "$channel" ];then
channel=cncwo
fi
t=`date +%s`
######echo "$key|$channel|$t|$ttl"
k=`echo -n "$key|$channel|$t|$ttl" |md5sum |cut -d' ' -f1`
echo -e k="\033[30m$k\033[0m"
echo -e "\033[40;37m$url?k=$k&channel=$channel&t=$t&ttl=$ttl\033[0m"
运行后的结果是这样:
[root@localhost workspace]# ./token.sh
Pls input the url(http://cncwo.cdn.cibn.cc/m3u8/4a39dc7ab2dbe801ddc94a8bdedc3656.m3u8):
Pls input the key(Hzx6iAj5lUfoEUwGHUl9s5YXSQCk1DOjpQX6XZ6tZq4jCNCWOO4FoLLTN0CI0ABn9RanSqsPHhmpEI0GEDIfFQzxnMNikKZcOYUZ):
Pls input the ttl(86400):
Pls input the channel(cncwo):
k=fd839ae262525b1ce39fc24a3ae76c7e
http://cncwo.cdn.cibn.cc/m3u8/4a39dc7ab2dbe801ddc94a8bdedc3656.m3u8?k=fd839ae262525b1ce39fc24a3ae76c7e&channel=cncwo&t=1543995980&ttl=86400
这下应该很清楚了吧,赶快行动起来操作吧-z-
引用文献:https://blog.csdn.net/u010339879/article/details/77938911