当前位置:   article > 正文

shell read 交互键入回车默认输入内容_shell 输入回车默认值

shell 输入回车默认值

很好理解,键入内容为回车的时候,内容肯定为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"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

运行后的结果是这样:

[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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这下应该很清楚了吧,赶快行动起来操作吧-z-

引用文献:https://blog.csdn.net/u010339879/article/details/77938911

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/547410
推荐阅读
相关标签
  

闽ICP备14008679号