【问题标题】:output returns nothing when running script运行脚本时输出不返回任何内容
【发布时间】: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 first If` 看起来很好,只要你在上面运行这个脚本主机名为server1 和server2的计算机
  • 顺便说一句,看起来more 在这里没有特别的意义。 config=$(grep security.tls.version.max <"$file") 会是更好的形式。 (请注意,local 定义应该在自己的行中;您可以将local file config tlsmax 放在函数的顶部——这样local 不会影响您为分配运行的命令的退出状态)。
  • 另外,你几乎肯定想要echo "$tlsmax",而不是echo "tlsmax"。请注意,== 不能保证在 [ ] 内可移植地工作——唯一的 POSIX 标准化字符串比较运算符是 =。

标签: bash solaris


【解决方案1】:

下面是shellcheck 的结果。这意味着第一行包含未关闭的"。正如@JNevill 所写,这是以local tlsmax 开头的行:

shellcheck myscript.sh 

In myscript.sh line 7:
     if [ "`hostname`" == "server1" ] || [ "`hostname`" == "server2" ];then
        ^-- SC1009: The mentioned parser error was in this test expression.
          ^-- SC1073: Couldn't parse this double quoted string.
           ^-- SC1072: Expected end of double quoted string. Fix any mentioned problems and try again.

对你有帮助吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-20
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 2013-05-01
    相关资源
    最近更新 更多