【问题标题】:Unix and Linux Cut command to equivalent with the For Loop DOS commandUnix 和 Linux Cut 命令等同于 For Loop DOS 命令
【发布时间】:2018-11-16 22:32:18
【问题描述】:

场景

我有这个 OpenSSL 命令,输出到管道进行切割。

openssl x509 -serial -noout -in cacert.pem | cut -d= -f2 > serial

我想只保留序列号,但要为 cmd 提供循环

openssl x509 -serial -noout -in cacert.pem
serial=E314E555E2D52FC8

我希望的结果示例

openssl x509 -serial -noout -in cacert.pem | FOR /F "tokens=2 delims==" %G IN ("pipe=result") DO @echo %G>serial

【问题讨论】:

    标签: windows loops for-loop command cut


    【解决方案1】:

    DOS 没有您正在尝试的 FOR 循环,但我怀疑您的意思不是 DOS,因为 OpenSSL 尚未移植到该操作系统。如果你指的是 Windows,那么你需要的命令是:

    (for /f "tokens=2 delims==" %a in ('openssl x509 -serial -noout -in cacert.pem') do @echo %a) > serial
    

    如果您将上述内容放在 .bat 文件中,则需要将 %a 更改为 %%a

    【讨论】:

    • 实际上,正如您所说的,它是关于 Windows 的。你给我的正确答案解决了我的问题。谢谢
    猜你喜欢
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多