У меня есть многострочная переменная, и я хочу только первую строку в этой переменной. Следующий скрипт демонстрирует проблему:
#!/bin/bash
STRINGTEST="Onlygetthefirstline
butnotthesecond
orthethird"
echo " Take the first line and send to standard output:"
echo ${STRINGTEST%%$'\n'*}
# Output is as follows:
# Onlygetthefirstline
echo " Set the value of the variable to the first line of the variable:"
STRINGTEST=${STRINGTEST%%$'\n'*}
echo " Send the modified variable to standard output:"
echo $STRINGTEST
# Output is as follows:
# Onlygetthefirstline butnotthesecond orthethird
Вопрос: Почему ${STRINGTEST%%$'\n'*}возвращается первая строка, когда ставится после echoкоманды, но заменяет символы новой строки пробелами, если ставится после присваивания?
$'...'вместо bash.