파일의 내용을 읽고 내용을 조작하고 다른 파일 (특히 가상 호스트 파일)에 추가하는 스크립트를 만들고 있습니다. 출력 파일의 서식과 공백은 중요하지만 내용을 쓸 때 공백이 제거됩니다.
VHOST_PATH="/etc/apache2/extra/httpd-vhosts.conf"
TEMPLATE_PATH="./template.conf"
TEMPLATE=$(<TEMPLATE_PATH)
# manipulating $TEMPLATE
echo $TEMPLATE #outputs correct whitespace
echo $TEMPLATE >> $VHOST_PATH #does not output correct whitespace
첫 번째 반향은
<VirtualHost *:80>
ServerAdmin webmaster@domain
DocumentRoot "root/web"
ServerName domain
ErrorLog "root/logs/error_log"
</VirtualHost>
그러나 파일에 들어가는 문자열은
<VirtualHost *:80> ServerAdmin webmaster@domain DocumentRoot "root/web" ServerName domain ErrorLog "root/logs/error_log" </VirtualHost>
대상 파일에 추가하는 동안 공백을 유지하려면 어떻게합니까? 나는 이것을 찾았지만 모든 유사한 질문은 스크립트를 다시 작성하지 않고 스크립트에 적용되지 않습니다.
echo $TEMPLATE것이 놀랍 습니다. 여러 공백도 축소해야합니다.