Answer the question
In order to leave comments, you need to log in
Is there a multidimensional array syntax in bash?
You have to keep 3 arrays of the same length.
namelist=("Россия" "Россия-2" "Латвия" "США" "Германия" "Швеция" "Нидерланды" "Япония")
latins=("russia" "russia-2" "latvia" "usa" "germany" "sweden" "netherlands" "japan")
loadlist=("Russia_freeopenvpn" "Russia-2_freeopenvpn" "Latvia_freeopenvpn" "freeopenvpn_USA" "Germany_freeopenvpn" "Sweden_freeopenvpn" "Netherlands_freeopenvpn" "freeopenvpn_Japan")
#!/bin/bash
set -e
arr=(\
("Россия" "russia" "Russia_freeopenvpn")\
("Россия-2" "russia-2" "Russia-2_freeopenvpn")\
("Латвия" "latvia" "Latvia_freeopenvpn")\
("США" "usa" "freeopenvpn_USA")\
("Германия" "germany" "Germany_freeopenvpn")\
("Швеция" "sweden" "Sweden_freeopenvpn")\
("Нидерланды" "netherlands" "Netherlands_freeopenvpn")\
("Япония" "japan" "freeopenvpn_Japan")\
)
for ((i=0; i < ${#arr[@]}; i++))
do
echo "${arr[$i]}"
done
$ ./test.sh
./test.sh: строка 6: ошибка синтаксиса около неожиданной лексемы `('
Answer the question
In order to leave comments, you need to log in
no, bash does not support multidimensional arrays.
But I see that all your names do not contain spaces, so store them in lines
#/bin/bash
arr=(
"Россия russia Russia_freeopenvpn"
"Россия-2 russia-2 Russia-2_freeopenvpn"
"Латвия latvia Latvia_freeopenvpn"
"США usa freeopenvpn_USA"
"Германия germany Germany_freeopenvpn"
"Швеция sweden Sweden_freeopenvpn"
"Нидерланды netherlands Netherlands_freeopenvpn"
"Япония japan freeopenvpn_Japan")
IFS=' ' read -r -a array <<< "${arr[1]}"
echo "name: ${array[0]}, smallname: ${array[1]}, vpnname: ${array[2]}"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question