【发布时间】:2018-08-24 14:01:33
【问题描述】:
当我运行这个脚本时,我什么也没有返回。有什么建议么?这是代码。
securityTlsVersion() {
local file="/usr/lib/firefox/mozilla.cfg"
local config=`more $file|grep security.tls.version.max`
local tlsmax="lockPref(\"security.tls.version.max`
if [ "`hostname`" == "server1" ] || [ "`hostname`" == "server2" ];then
if [ "$config" = "" ]; then
echo "Adding security.tls.version.max line to mozilla.cfg"
echo "tlsmax >> $file
echo "security.tls.version.max is now configured"
else
echo "security.tls.version.max is already configured"
fi
fi
}
【问题讨论】:
-
通过指出您想要完成的内容以及您对代码的期望,帮助其他尝试回答您的问题的用户。
-
请在您的源代码上使用代码格式。您可以使用编辑窗口上的
{}按钮添加代码格式。 -
我猜这行是错误的:local **tlsmax="lockPref(\"security.tls.version.max
** Unmatched backtick and unmatched double quote. Your firstIf` 看起来很好,只要你在上面运行这个脚本主机名为server1和server2的计算机 -
顺便说一句,看起来
more在这里没有特别的意义。config=$(grep security.tls.version.max <"$file")会是更好的形式。 (请注意,local定义应该在自己的行中;您可以将local file config tlsmax放在函数的顶部——这样local不会影响您为分配运行的命令的退出状态)。 -
另外,你几乎肯定想要
echo "$tlsmax",而不是echo "tlsmax"。请注意,==不能保证在[ ]内可移植地工作——唯一的 POSIX 标准化字符串比较运算符是=。