Linux Bash for循环语法解释

Linux Bash for循环语法解释,linux,bash,Linux,Bash,我在Bash shell Linux操作系统中工作。我有以下for循环: for ((i=0;i<${#listModels[@]};i++)) do var=${listVersion[$i]} if [ ${!var} ] then export MY_LIBRARY_PATH=$MY_LIBRARY_PATH:$ROOT_PATH/${listModels[$i]}/${listModels[$i]}_${!var} else echo ">>>&g

我在Bash shell Linux操作系统中工作。我有以下for循环:

for ((i=0;i<${#listModels[@]};i++))
do
var=${listVersion[$i]}
if [ ${!var} ]
then
    export MY_LIBRARY_PATH=$MY_LIBRARY_PATH:$ROOT_PATH/${listModels[$i]}/${listModels[$i]}_${!var}
else
    echo ">>>> No ${listModels[$i]} version! <<<<"
fi
done

这个概念是MODEL1、MODEL2和MODEL3不时地变化,例如它变成MODEL1.1、MODEL2.2,。。我希望每次listVersion值更改时,脚本都会修改我的路径。但是有谁能解释for循环的具体功能(尤其是[@]和[$i]之类的东西)。我是Bash新手,只知道基本命令。提前谢谢

manbash
中所述,
${#array[@]}
返回数组中的元素数。类似地,
${array[$i]}
(最好写为
${array[i]}
)返回数组的
$i
-th元素

#! /bin/bash
array=( a b c )
echo Size: ${#array[@]}
echo First: ${array[0]}
echo Second: ${array[1]}
echo Last: ${array[-1]}  # Negative index counts from the right!

manbash
中所述,
${#array[@]}
返回数组中的元素数。类似地,
${array[$i]}
(最好写为
${array[i]}
)返回数组的
$i
-th元素

#! /bin/bash
array=( a b c )
echo Size: ${#array[@]}
echo First: ${array[0]}
echo Second: ${array[1]}
echo Last: ${array[-1]}  # Negative index counts from the right!

允许从bash 4.2进行IIRC负索引if语句
if[${!var}]
中的表达式表示
i-th
元素不存在?允许从bash 4.2进行IIRC负索引if语句
if[${!var}]
中的表达式表示
i-th
元素不存在?