Çok satırlı bir değişkenim var ve yalnızca bu değişkenin ilk satırını istiyorum. Aşağıdaki komut dosyası sorunu gösterir:
#!/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
Soru: ${STRINGTEST%%$'\n'*}Komuttan sonra yerleştirildiğinde neden ilk satırı echodöndürüyor, ancak atamadan sonra satırları boşlukla değiştiriyor?
$'...'Bash yerine desteklemeyen bir kabukla çalıştırmaya çalışmak gibi bir kullanıcı hatası gibi görünüyor .