bash cgi script with chinese
Added by linuxier over 14 years ago
I simply use the default lighttpd.conf but just enable the cgi module.
The script listed bellow just works fine in the urxvt, with proper Chinese characters output. However, when visited by a browser, these Chinese characters just gone, leaving no spaces?If substitute "/usr/bin/fortune-zh" with "/usr/games/fortune" which outputs just English words, every thing is ok. So, How to get it done with Chinese ouput in a browser?
$cat for
#!/bin/sh echo "Content-type: text/html" echo "" echo "<html><head>"; echo '<meta http-equiv=Content-Type content="text/html; charset=utf-8">'; echo "<title>Fortune</title>"; echo "</head><body>"; for myline in $(/usr/bin/fortune-zh | sed -e '1,$ s/.[[0-9]*m//g' -e '1,$ s/ /__s__/g' -e '1,$ s/\t/__t__/g' ) do myline=$(echo $myline | sed -e '1,$ s/__s__/ /g' -e '1,$ s/__t__/\t/g') echo "<pre>$myline</pre>" done echo "</body></html>"; #
$uname -a
Linux myhost 2.6.30-2-amd64 #1 SMP Mon Dec 7 05:21:45 UTC 2009 x86_64 GNU/Linux
$sudo lighttpd -v
lighttpd: Symbol `FamErrlist' has different size in shared object, consider re-linking
lighttpd/1.4.25 (ssl) - a light and fast webserver
Build-Date: Jan 5 2010 11:12:25
$iceweasel -v
Mozilla Iceweasel 3.5.6, Copyright (c) 1998 - 2009 mozilla.org