Answer the question
In order to leave comments, you need to log in
How to increment a value in a bash associative array?
Good afternoon. There is a small associative array with a large number of values and keys. And so, there was an idea to simplify it by means of incrementation of values.
The array itself:
declare -A host
host[192.168.1.1]='test1.ru'
host[192.168.1.2]='test2.ru'
host[192.168.1.3]='test3.ru'
host[192.168.1.4]='test4.ru'
host[192.168.1.5]='test5.ru'
first = 1
host[192.168.1.1]='test$first.ru'
Answer the question
In order to leave comments, you need to log in
in a string, you need to escape the variable using curly braces
first=1
echo "test${first}.ru"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question