여러 줄 변수가 있으며 해당 변수의 첫 번째 줄만 원합니다. 다음 스크립트는 문제를 보여줍니다.
#!/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
질문 : 명령 ${STRINGTEST%%$'\n'*}뒤에 배치 할 때 첫 번째 줄을 반환하는 이유는 무엇입니까? echo그러나 할당 후에 배치 할 때 줄 바꿈을 공백으로 바꾸는 이유는 무엇 입니까?
$'...'bash 대신 지원하지 않는 쉘로 실행하려고하는 것과 같은 사용자 오류처럼 들립니다.