我很难理解为什么bash -e选项会退出这个脚本。只有当计算出的表达式给出0时,才会发生这种情况
#!/bin/bash
set -ex
table_year=( 1979 1982 1980 1993 1995 )
year=$1
let indice=year-1
real_year=${table_year[$indice]}
echo OK $real_year在以下情况下可以使用Is:
./bash_test_array 2但不是什么时候:
./bash_test_array 1 在这种情况下,indice等于0。为什么-e选项会导致退出?
发布于 2015-03-31 19:17:02
您可以使用以下技巧:
let indice=year-1 || truehttps://stackoverflow.com/questions/29367309
复制相似问题