问题
I'm using this bash CGI:
#!/usr/bin/sh
echo "Content-type: text/html"
echo ""
echo `ls -al`
And it produces ie:
total 52 drwxrwxrwx. 2 root root 4096 Feb 2 18:34 . drwxr-xr-x. 8 root root 4096 Feb 2 17:58 .. -rw-r--r--. 1 root root 36310 Feb 2 17:45 dds.jpg -rw-rw-rw-. 1 user user 50 Feb 2 18:03 dds_panel.htm -rwxrwxrwx. 1 user user 460 Feb 2 18:34 test-cgi.cgi
In a terminal they appear each neatly on a single line but in the browser they appear all on the same line. What's the best way to keep the formatting?
回答1:
If you do not need any html formatting, simply change the content-type to text/plain
.
If you need html formatting your output should contain a complete html page. In this case surround your output with <pre>
, replace newlines with <br>
or convert your output in something like a list or table.
来源:https://stackoverflow.com/questions/28284475/keep-line-formatting-in-browser-with-bash-cgi