【问题标题】:'Missing name for redirect.' error in while running command in CSH environment“缺少重定向名称。”在 CSH 环境中运行命令时出错
【发布时间】:2023-03-26 13:41:01
【问题描述】:

我正在尝试在 CSH 环境中使用以下命令生成一些证书:

/usr/bin/openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout "selfsigned.key" \
-out "selfsigned.crt" -subj "/C=XX/ST=XX/L=XX/O=XX/OU=XX/CN=Some IP" -extensions SAN \
-config <(cat /etc/ssl/openssl.cnf <(printf "\n[SAN]\nsubjectAltName=DNS:Some DNS,Some IP"))

得到 Missing name for redirect 错误。

我该如何解决这个问题?

【问题讨论】:

    标签: linux shell csh


    【解决方案1】:

    你的命令行的一部分是:

    … <(cat /etc/ssl/openssl.cnf <(printf "\n[SAN]\nsubjectAltName=DNS:Some DNS,Some IP"))
    

    您使用了 Bash 特定的符号 — process substitution — 两次。在 C shell 中,这根本行不通。 C shell 不知道你的意思(看看错误信息)。

    您必须将命令包装在 Bash 脚本中并使用 Bash 执行它。或者重新考虑命令,以便根本不使用进程替换。

    一种选择是创建一个临时文件并在命令中使用它:

    set tmpfile `mktemp`
    cat /etc/ssl/openssl.cnf > $tmpfile
    printf "\n[SAN]\nsubjectAltName=DNS:Some DNS,Some IP\n" >> $tmpfile
    /usr/bin/openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout "selfsigned.key" \
        -out "selfsigned.crt" -subj "/C=XX/ST=XX/L=XX/O=XX/OU=XX/CN=Some IP" -extensions SAN \
        -config $tmpfile
    rm -f $tmpfile
    

    如果中断可能会留下临时文件,这是标准建议不要在 C shell 中编写脚本的原因之一。 (参见C Shell Programming Considered HarmfulTop Ten Reasons not to use the C shell。)使用POSIX shell,您可以确保删除临时文件,除非您使用SIGKILL 粗暴地终止脚本。

    【讨论】:

      猜你喜欢
      • 2021-03-11
      • 2013-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多