![このBashリスト式と変数呼び出しが失敗するのはなぜですか? [閉鎖]](https://linux33.com/image/97459/%E3%81%93%E3%81%AEBash%E3%83%AA%E3%82%B9%E3%83%88%E5%BC%8F%E3%81%A8%E5%A4%89%E6%95%B0%E5%91%BC%E3%81%B3%E5%87%BA%E3%81%97%E3%81%8C%E5%A4%B1%E6%95%97%E3%81%99%E3%82%8B%E3%81%AE%E3%81%AF%E3%81%AA%E3%81%9C%E3%81%A7%E3%81%99%E3%81%8B%EF%BC%9F%20%5B%E9%96%89%E9%8E%96%5D.png)
パスワード
#!/bin/bash
startTimes=$(seq 300 10 330)
for startTime in ${startTimes[@]};
do
endTime=${startTime}+10
echo ${endTime} > /tmp/111test # Output literally: startTimes+10
done
echo "Last endTime: "${endTime}
に出力bash -x ...
++ seq 300 10 330
+ startTimes='300
310
320
330'
+ for startTime in '${startTimes[@]}'
+ endTime=300+10
+ echo 300+10
+ for startTime in '${startTimes[@]}'
+ endTime=310+10
+ echo 310+10
+ for startTime in '${startTimes[@]}'
+ endTime=320+10
+ echo 320+10
+ for startTime in '${startTimes[@]}'
+ endTime=330+10
+ echo 330+10
+ echo 'Last endTime: 330+10'
Last endTime: 330+10
期待される出力
310
320
330
340
オペレーティングシステム: Debian 8.5
Linux カーネル: 4.6 backsports
答え1
コメントのdon_crisstiの答えは、出力で使用する必要があるstartTimes
宣言と使用の2つのエラーを指摘しています。${var[@]}
seq
startTimes=( $(seq 300 10 330) )
for startTime in "${startTimes[@]}";
do
endTime=$(( ${startTime}+10 ))
echo ${endTime} > /tmp/111test
done
echo "Last endTime: "${endTime}