linux - 从 bash 脚本中的数字显示月份

标签 linux bash shell unix

我试图证明,如果您输入月份的内容,它会显示月份 例如 january=1, february=2 , march=3 ...

和年份 2012,2013,2014...

但是,如果您输入的月份大于 12,它应该会告诉您 “抱歉”,而我无法弄清楚如何使该消息生效。

echo " please type a number for a month"
read month
echo " please type a number for a year"
read year

if [ "$month" = "1-12" ]
then
        cal "$month" "$year"
        sleep 2
        echo " thank you, good bye... "
else
        echo " sorry "  
        sleep 2
fi

最佳答案

if [[ $month -lt 13 && $month -gt 0  ]]  
then
        cal "$month" "$year"
        sleep 2
        echo " thank you, good bye... "
else
        echo " sorry "  
        sleep 2
fi

关于linux - 从 bash 脚本中的数字显示月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15443768/

相关文章:

node.js - 英雄库: "bash: ./start.sh: Permission denied"

arrays - 将多行字符串转换为数组

linux - 如何直接从 git bash 创建一个 github 存储库?

linux - 在单个文件中接受多个用户输入的 Shell 脚本

c - lseek 中的 Offset(2nd) 参数

c - 测量内核 2.4.37 中的时间流逝

linux - 如何将容器导入到 ACR 并将其配置为 Linux 平台容器?

linux - 配置 glibc : Need linker with . init_array/.fini_array 支持时出错

bash - 在 block bash 脚本中写入多行

c - 如何在 chroot jail 中执行 shell 命令