[英]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.