【发布时间】:2015-06-04 17:08:04
【问题描述】:
我很难理解为什么 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
当:
./bash_test_array 2
但不是什么时候:
./bash_test_array 1
indice 在这种情况下是否等于0。为什么-e 选项会导致退出?
【问题讨论】:
-
@Joe:虽然原因可能相同,但这个问题的表达方式比其他问题简单得多(赋值与增量副作用)。
标签: bash arithmetic-expressions