编写一个程序,如果月的某一天在3月20日和6月20日之间,则打印true,否则使用shell脚本打印false #/bin/bash-x 阅读-p“输入日期:-”日期 阅读-p“输入月份:-”月份 如果(($Month
这里有一个想法:编写一个程序,如果月的某一天在3月20日和6月20日之间,则打印true,否则使用shell脚本打印false #/bin/bash-x 阅读-p“输入日期:-”日期 阅读-p“输入月份:-”月份 如果(($Month,shell,Shell,这里有一个想法: #!/bin/bash -x read -p " Enter Date:-" date read -p " Enter Month:-" Month if (( ($Month <= 6 & $date <= 20) )) then echo $Month $date "True"; elif (( ($Month >= 3 & $Month < 6) &a
#!/bin/bash -x
read -p " Enter Date:-" date
read -p " Enter Month:-" Month
if (( ($Month <= 6 & $date <= 20) ))
then
echo $Month $date "True";
elif (( ($Month >= 3 & $Month < 6) & ($date<31) ))
then
echo $date $Month "True";
else
echo "False";
fi
使用此代码,它可以正常工作;不要使用
elif
中的条件,否则它将无法工作
#!/bin/bash
read -p "Enter Date: " date
read -p "Enter Month: " Month
# should validate input: non-blank, numeric
combo=0
res="false"
st=1
if [ $Month -ge 3 -a $Month -le 6 ]; then
# 30 for Apr, Jun
# 31 for Mar, May
dlimit=$((30 + (Month % 2)))
if [ $date -ge 1 -a $date -le $dlimit ]; then
combo=$(((Month * 100) + date))
# true Mar 20 to Jun 20
if [ $combo -ge 320 -a $combo -le 620 ]; then
res="true"
st=0
fi
fi
fi
echo "$Month/$date $res"
exit $st
!/bin/bash-x
阅读-p“输入日期:-”日期
阅读-p“输入月份:-”月份
如果(($Month)and运算符是&&&
,这里有什么问题吗?
#!/bin/bash -x
read -p " Enter Date:-" date
read -p " Enter Month:-" Month
if (( ($Month <= 6 && $date <= 20) && (($Month >= 3 && $date <= 20) && ($date<31)) ))
then
echo $Month $date "True";
else
echo "False";
fi