Eu tenho uma variável multilinha e quero apenas a primeira linha nessa variável. O script a seguir demonstra o problema:
#!/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
Pergunta: Por que ${STRINGTEST%%$'\n'*}retornar a primeira linha quando colocada após um echocomando, mas substituir novas linhas por espaços quando colocadas após a atribuição?
$'...'vez de bash.