Ho una variabile multilinea e voglio solo la prima riga in quella variabile. Il seguente script dimostra il 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
Domanda: Perché ${STRINGTEST%%$'\n'*}restituisce la prima riga quando viene posizionata dopo un echocomando, ma sostituisce le nuove righe con spazi quando viene posizionata dopo l'assegnazione?
$'...'invece di bash.