繁体   English   中英

如何在HTML中使用Shell脚本放置列表的值

[英]how to put list's value using shell script in html

场景:我从包含值集的python中获取列表变量,我想将这些列表值放在正在运行时生成的html文件中。

testmail.sh

**猫<< EOF >〜/ ** test.html

<html>

<head>
    <title>

    My System information

    </title>

</head>

<body>

<h1> My system information : </h1>

for“ $ @”中的值//这包含从python接收的列表值。

$值

完成

</body>

</html>

紧急行动

上面的代码在testmail.sh中,它生成显示值的test.html。

但我希望将此值以适当的格式放在html主体中。.但它不起作用...

我假设您确实在使用bash脚本,而不使用“ $ @”参数,因为这没有意义。 =)

输出示例:

$ echo -e "one\n two\n three" | bash foo.html 
<html>
<p>one</p>
<p>two</p>
<p>three</p>
</html>

执行此操作的Shell脚本:

$ cat foo.html 
cat <<END
<html>
END
while read LINE
do
echo "<p>${LINE}</p>"
done
cat <<END
</html>
END

像这样吗

python script.py |
sed -e '1i\<ul>' -e 's%.*%<li>&</li>%' -e '$a\</ul>'

...但是最好还是在Python脚本中添加一个选项以产生HTML(ish)输出。

如果要从Python驱动Shell脚本,也可以在Python中进行HTML格式化。

import subprocess

pipe = subprocess.Popen("testmail.sh", stdin=subprocess.PIPE)
pipe.stdin.write('<ul>\n')
for item in correctList:
    pipe.stdin.write('<li>%s</li>\n' % item)
pipe.stdin.write('</ul>\n')
pipe.stdin.close()

假设您的testmail.sh从标准输入中读取其数据,这显然还不是这种情况,因此您需要稍作更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM