I'm trying to redirect a echo to file but the carriage returns(\r) are inserted as ^M. This is the command I'm using
echo -e "<VirtualHost *:80>
\r DocumentRoot /var/www/html
\r ServerName site
\r ServerAlias site
\r ErrorLog \"/var/log/apache2/html-error.log\"
\r LogFormat \"%t<>%u<>%h<>%O<>%T<>%>s<>%{Referer}i<>%r<>%{User-Agent}i\" combined
\r CustomLog \"/var/log/apache2/html-access.log\" combined
\r RewriteEngine on
\r RewriteCond %{SERVER_NAME} =site
\r RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
\r</VirtualHost>\n" > teste.txt
This is what it looks in the file:
<VirtualHost *:80>
^M DocumentRoot /var/www/webapp
^M ServerName iqnus.bvloja.com
^M ServerAlias iqnus.bvloja.com
^M ErrorLog "/var/log/apache2/webapp-error.log"
^M LogFormat "%t<>%u<>%h<>%O<>%T<>%>s<>%{Referer}i<>%r<>%{User-Agent}i" combined
^M CustomLog "/var/log/apache2/webapp-access.log" combined
^M RewriteEngine on
^M RewriteCond %{SERVER_NAME} =iqnus.bvloja.com
^M RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
^M</VirtualHost>
CodePudding user response:
You're probably looking for \n
instead of \r
. A new line on a non-Windows machine would be just \n
, or if you're on Windows it would be \r\n
.
CodePudding user response:
the -e flag enables the interpretation of backslash escapes. Just use echo instead of echo -e.