2013-07-18 116 views
3

我遇到了shell脚本的问题,希望您可以帮忙。
我想优化下面的代码的HTML格式:Linux busybox 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 

我删除了回声-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脚本。
这可能是问题吗?

+0

感谢试图帮助的人。 我应该在一开始就让这个问题更清楚,因为这有点令人困惑。 问题解决了。 –

回答

0

我终于找到了解决办法:

#! /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的外壳并没有正确显示在vi编辑器粘贴的标签,所以我用set:noai。
设置:noai解决了标签问题,但在html代码之后有这个额外的行。
解决方案是使用\ c转义字符。
如果有人有更好的答案,随时张贴它。

0

无需回声-e和报价,

cat <<eof> shellhtml.htm 
<html> 
</html> 
eof 

这工作。

0

非常接近:-)你不需要echo

#! /bin/sh 
cat <<EOF > myfile 
<html> 
    <head> 
    <title></title> 
    </head> 
     <body> 
     <p>Text</p> 
     </body> 
</html> 
EOF 
0

将!#/ bin/sh添加到顶部,并删除以EOF开头的行和EOF之前的单引号行。然后你的html将被正确地传递给myfile。

所以正确的shell脚本将是: -

#!/bin/sh 
cat <<EOF > myfile 
<html> 
<head> 
<title></title> 
</head> 
    <body> 
    <p>Text</p> 
    </body> 
</html> 
EOF 
+0

我试过这个,但是它没有在html页面上显示任何东西,因为它使用echo。 –

+0

输出应该位于名为myfile的文件中。对我来说它是完美的。 – Yehuda

+0

它仍然无法正常工作。 可能是什么问题? 我真的需要这个答案。 –