Tengo una variable multilínea, y solo quiero la primera línea en esa variable. El siguiente script demuestra el 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
Pregunta: ¿Por qué ${STRINGTEST%%$'\n'*}devuelve la primera línea cuando se coloca después de un echocomando, pero reemplaza las nuevas líneas con espacios cuando se coloca después de la asignación?
$'...'lugar de bash.