小编use*_*938的帖子

Shell 脚本:在 if 语句中定义变量

在 shell 程序中,我想在 if 语句中定义一个月份变量,如下所示。但我似乎无法在 if 语句中定义变量 - 我不断收到一条错误消息,提示“未找到命令 'dmonth'”。任何帮助都感激不尽!

    #Enter date:

    echo "Enter close-out date of MONTHLY data (in the form mmdd): "
    read usedate
    echo " "

    #Extract first two digits of "usedate" to get the month number:

    dmonthn=${usedate:0:2}
    echo "month number = ${dmonthn}"
    echo " "

    #Translate the numeric month identifier into first three letters of month:

    if [ "$dmonthn" == "01" ]; then
        dmonth = 'Jan'
    elif [ "$dmonthn" == "02" ]; then 
        dmonth = "Feb" …
Run Code Online (Sandbox Code Playgroud)

variables shell if-statement

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

if-statement ×1

shell ×1

variables ×1