[英]Linux busybox shell script html formatting
我在使用 shell 脚本时遇到问题,希望您能提供帮助。 我想优化以下代码的 HTML 格式:
#! /bin/sh
cat <<EOF > myfile # temporary file
#! /bin/sh
echo -e "Content-type: text/html; charset=iso-8859-1\n\n"
echo -e "<html><head>\c"
echo -e "<title></title>"
echo -e "</head>"
echo -e "<body>\c"
echo -e "<p>Text</p>"
echo -e "</body></html>"
EOF
chmod 777 myfile
mount -o bind myfile myfile # mount temporary on the original myfile
rm myfile
我删除了echo -e
和双引号。 我也试过这个:
#! /bin/sh
cat <<EOF > myfile # temporary file
#! /bin/sh
echo -e '
<html>
<head>
<title></title>
</head>
<body>
<p>Text</p>
</body>
</html>
'
EOF
chmod 777 myfile
mount -o bind myfile myfile # mount temporary on the original myfile
rm myfile
脚本有什么问题?
注意:上面的代码是 .cfg 文件的内容,每次重启都会加载它。 .cfg 文件然后将 EOF 标记之间的内容粘贴到 myfile 中,这是一个 CGI 脚本。
这可能是问题吗?
不需要 echo -e 和引号,
cat << eof > shellhtml.htm
<html>
</html>
eof
这有效。
非常接近:-) 你不需要echo
。
#! /bin/sh
cat <<EOF > myfile
<html>
<head>
<title></title>
</head>
<body>
<p>Text</p>
</body>
</html>
EOF
将!#/bin/sh 添加到顶部,并删除以echo e 开头的行,以及EOF 前带单引号的行。 然后你的 html 将被正确地传送到 myfile。
所以正确的shell脚本将是:-
#!/bin/sh
cat <<EOF > myfile
<html>
<head>
<title></title>
</head>
<body>
<p>Text</p>
</body>
</html>
EOF
我终于找到了解决方案:
#! /bin/sh
cat <<EOF > myfile # temporary file
#! /bin/sh
echo -e "Content-type: text/html; charset=iso-8859-1"
echo -e "
<html>
<head>
<title></title>
</head>
<body>
<p>Text</p>
</body>
</html>\c"
EOF
chmod 777 myfile
mount -o bind myfile myfile # mount temporary on the original myfile
rm myfile
busybox shell 没有在 vi 编辑器中正确显示粘贴的选项卡,所以我使用了 Vim 的set: noai
命令。
set: noai
解决了tab 的问题,但是HTML 代码后面多了一行。
对此的解决方案是使用\\c
转义字符。
如果有人有更好的答案,请随时发布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.