Keep line formatting in browser with bash CGI

寵の児 提交于 2019-12-12 03:26:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!