【发布时间】:2016-01-04 22:55:49
【问题描述】:
我正在编写一个 bash 脚本来自动化一些 opencv 代码,我需要多次运行这些代码并输入一组变量。 出于某种原因,尽管当我尝试将 0 分配给标志变量时,我的 bash 脚本不断崩溃。 我也在 if 循环之外尝试过这个,它也会导致脚本崩溃。
#!/bin/bash
set -e
# Build most recent code
cd build2/
cmake ..
make
Scale=(9 9)
inputType="scale"
flag=1
counter=0
for i in ${Scale[@]}; do
echo iteration: $counter
if [ $counter -eq 0 ]
then
echo first iteration
let flag=0 #Crashes Here
echo after assignment $flag
else
echo not first iteration
let flag=1 #Doesn't crash here
echo after assignment $flag
fi
echo starting program
#Note 1.inputValue 2.Input Type 3.firstGo
./multiDimen ${i} $inputType $flag
echo Test Type is: $inputType
let counter=counter+1
done
echo Done
有什么理由会这样吗?
【问题讨论】:
-
它只会退出,没有任何错误消息
-
在我用 = 替换 let 之后,虽然它开始正常工作,但一定是不正确地使用 let 使用它来将变量分配给 0 ??
标签: bash variables variable-assignment