вы должны обработать этот материал в индексе evals. и вы можете косвенно через индексы вашей косвенной переменной, если вы сделаете ее массивом.
a=(abc1 def2 ghi3 jkl4 mno5)
r=('a[c=${#a[@]}]' a\[i] a\[@])
for i in 0 1 2 3 4 5
do c=
printf "<%s>\n" "${!r-${!r[i<c?1:2]}}"
printf "\n\tindex is $i and count is $c\n\n"
done
<abc1>
index is 0 and count is 5
<def2>
index is 1 and count is 5
<ghi3>
index is 2 and count is 5
<jkl4>
index is 3 and count is 5
<mno5>
index is 4 and count is 5
<abc1>
<def2>
<ghi3>
<jkl4>
<mno5>
index is 5 and count is 5
Поскольку индексы bash
отсчитываются от 0, общее количество объектов массива всегда будет на единицу больше, чем самый высокий установленный индекс, и поэтому:
c=
echo "${a[c=${#a[@]}]-this index is unset}" "$c"
this index is unset 5
... параметр расширяется до слова по умолчанию, если таковое имеется.
Если он не предоставлен:
c=
${!r}
echo "$c"
5
... никакого вреда нет.
В цикле я отслеживаю переменную $ i
ndex и проверяю, не меньше ли она $ c
ount. Когда он меньше, я расширяю ссылочную переменную $ r
до a [i]
, потому что это действительный индекс, но когда он равен или больше, я расширяю $ r
ef для всего массива $ a
.
Вот он в функции:
ref_arr(){
local index=-1 count=
local ref=( "$1[ count= \${#$1[@]} ]"
"$1[ index ]" "$1[ @ ]"
) && printf "input array '%s' has '%d' members.\n" \
"$1" "${!ref-${count:?invalid array name: "'$1'"}}"
while [ "$((index+=1))" -lt "$count" ]
do printf "$1[$index] == '%s'\n" "${!ref[1]}"
done
}
some_array=(some "dumb
stuff" 12345\'67890 "" \
'$(kill my computer)')
ref_arr some_array
ref_arr '$(echo won'\''t work)'
input array 'some_array' has '5' members.
some_array[0] == 'some'
some_array[1] == 'dumb
stuff'
some_array[2] == '12345'67890'
some_array[3] == ''
some_array[4] == '$(kill my computer)'
bash: count: invalid array name: '$(echo won't work)'
Не уверен, что на этот вопрос когда-либо был дан ответ, но у меня была такая же проблема, и в итоге я установил все шрифты Google, которые решили мою проблему.
sudo curl https://raw.githubusercontent.com/qrpike/Web-Font-Load/master/install.sh | bash
Сообщение encase кто-то еще столкнулся с этим.