Answer the question
In order to leave comments, you need to log in
Nested loop not working in bash Why?
Good afternoon!
Almost for the first time I work with bash, it was required to go through the whole list of links with the parser, each link has pagination. There is a php script that parses all this, and everything is launched from bash, which is arranged like this:
#!/bin/bash
# Создаем массив с ссылками для парсинга, после разделителя - кол-во страниц для парсинга по ссылке
declare -A site
site[0]="https://site.ru/;50"
site[1]="https://site.ru/;10"
site[2]="https://site.ru/;100"
# Обходим массив ссылок
for key in "${!site[@]}"; do
echo "Key: ${key}"
echo "Value: ${site[$key]} \n\r"
echo "=============================================="
set -f; IFS=";"; arr=${site[$key]}
# Вот тут далее не работает. Проблема с cnt, если вместо нее вставить цифру (например 50) то цикл работает
lnk=${arr[0]}
cnt=${arr[1]}
for (( i=1; i <= $cnt; i++ ))
do
echo -e "Page number is " $i " in cat " $lnk "\n\r"
/usr/local/lsws/lsphp73/bin/php -f parser.php $lnk $i
done
done
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question