J'ai une variable multiligne et je veux seulement la première ligne de cette variable. Le script suivant illustre le problème:
#!/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
Question: Pourquoi ${STRINGTEST%%$'\n'*}retourne la première ligne lorsqu'elle est placée après une echocommande, mais remplace-t-elle les retours à la ligne par des espaces lorsqu'elle est placée après l'affectation?
$'...'au lieu de bash.