我正在编写一个脚本,它应该根据环境的使用类型和发布日期在环境上安装修补程序。为此,我需要检查环境类型,然后检查修补程序的发布日期。如果环境的使用类型为prod,并且自修补程序发布以来已经过time1秒数,则安装修补程序。
通过阅读网站上类似的问题,我想到了这一点。
u=( prod test dev)
t=( time2 time2 time3 )
# where t represents the number of seconds that must pass after the release date in order for the hotfix to be installed
for ((i=0;i<${#u[@]};i++))
do
if ($usage_type=${u[i]} && $hf_release_date -ge $current_time+${t[i]}); then install_hotfix; fi
done上面的代码会按预期工作吗?
编辑:
我试着修正了语法,但还是遗漏了一些东西:
u=( prod test dev)
t=( time2 time2 time3 )
# where t represents the number of seconds that must pass after the release date in order for the hotfix to be installed
for ((i=0;i<${#u[@]};i++))
do
if [[ "$usage_type" == "${u[i]}" ]] && [[ "$hf_release_date" -ge "$current_time"+"${t[i]}" ]]; then install_hotfix; fi
done发布于 2020-04-27 19:02:41
如果你的问题是“如何迭代两个数组”,你可以通过运行下面的代码片段来检查这部分代码是否正确:
u=( prod test dev)
t=( time2 time2 time3 )
for ((i=0;i<${#u[@]};i++))
do echo "u[$i] = ${u[i]}, t[$i] = ${t[i]}"
done输出:
u[0] = prod, t[0] = time2
u[1] = test, t[1] = time2
u[2] = dev, t[2] = time3https://stackoverflow.com/questions/61454691
复制相似问题