Цикл for Bash

Содержание
Пример
Перебор массива
Похожие статьи

Пример

Простейший пример цикла for

#!/bin/bash for i in $(seq 1 10); do echo $i done

./for_loop.sh

1 2 3 4 5 6 7 8 9 10

Цикл for … in по массиву

Для создания массива нужно воспользоваться declare -a.

Для перебора элементов используется следующий синтаксис

for i in "${arr[@]}"

Обратите внимание на отсутствие запятых между элементами.

#!/bin/bash declare -a urls=("https://beget.com" "https://heihei.ru" "https://testsetup.site" ) for url in "${urls[@]}" do echo "$url" done

./for_array.sh

https://beget.com https://heihei.ru https://testsetup.site

Article author: Andrei Olegovich

Похожие статьи
Bash
Bash Scripting
-eq -gt …: Операторы сравнения
if else: Условные операторы
Цикл while
date: Дата
Переход на новую строку
Арифметические операции
Передать файл или пароль по SFTP в Bash скрипте
Errors Bash

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: