Вот несколько способов создания цикла Bash с многострочной строкой, а также примеры кода:
Метод 1: использование документа здесь
#!/bin/bash
# Here Document
while IFS= read -r line; do
echo "$line"
done << EOF
This is a multiline
string using a Here Document.
EOF
Метод 2: использование строки
#!/bin/bash
# Here String
while IFS= read -r line; do
echo "$line"
done <<< $'This is a multiline\nstring using a Here String.'
Метод 3. Использование массива
#!/bin/bash
# Array
lines=("This is a multiline" "string using an Array.")
for line in "${lines[@]}"; do
echo "$line"
done
Метод 4. Использование переменной с символом новой строки
#!/bin/bash
# Variable with Newlines
lines="This is a multiline
string using a variable with newlines."
while IFS= read -r line; do
echo "$line"
done <<< "$lines"
Метод 5: использование команды printf
#!/bin/bash
# printf Command
printf -v lines '%s\n' "This is a multiline" "string using the printf command."
while IFS= read -r line; do
echo "$line"
done <<< "$lines"