【问题标题】:How to Include Variables in a File Name used in a Variable $File Equals如何在变量 $File Equals 中使用的文件名中包含变量
【发布时间】:2021-08-03 01:17:23
【问题描述】:

为什么回显不返回 - /lsf10/monitors/lpstat_email_1_vmobius_05122021.txt? 它返回 --> $FILE

#!/usr/bin/ksh
integer max=3
integer i=1
while [[ $i -lt $max ]]
do
today=`date +%m%d%Y`
FILE = "/lsf10/monitors/lpstat_email_$i_vmobius_$today.txt"
echo "the $FILE"

echo $i
echo "the $FILE"
(( i = i + 1 ))
done
 

【问题讨论】:

    标签: ksh aix


    【解决方案1】:

    在变量周围使用 ${...} 以在字符串文字中进行插值 - 它使事情更清晰并有助于解释器。

    缩进有助于提高可读性和可维护性。

    试试这个:

    #!/usr/bin/ksh
    integer max=3
    integer i=1 
    while (( i < max ))
    do
        today=`date +%m%d%Y`
        FILE="/lsf10/monitors/lpstat_email_${i}_vmobius_${today}.txt"
        echo "the $FILE"
        echo $i
        echo "the $FILE"
        (( i ++ ))
    done
    

    【讨论】:

    • 日期效果很好 - 但没有填充 $i - 它返回为 --> /lsf10/monitors/lpstat_email_05122021.txt
    猜你喜欢
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多