linux - 使用 awk 的输出来运行命令

标签 linux bash shell awk

我是 shell 脚本的新手,似乎无法解决这个看似简单的任务。我有一个大约 250 行的文本文件 (ciphers.txt),我想将每行的第一列用作命令中的参数。任何帮助将不胜感激!

命令是:

openssl s_client -connect host:port -cipher argument

当我一次执行一个时它工作正常,但我真的不想运行相同的命令 250 次以上。到目前为止,这是我的脚本:

awk '{command = "openssl s_client -connect localhost:4433 -cipher > results.txt"
print $0 | command}' ciphers.txt

我一直收到错误,所以我很确定我在某处有语法错误。 awk 的输出是否附加在 -cipher 之后?

最佳答案

在 awk 中使用 system:

awk '{ system("openssl s_client -connect host:port -cipher " $1) }' ciphers.txt

关于linux - 使用 awk 的输出来运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20389799/

相关文章:

linux - 为什么管道输入 BASH 命令组有时会起作用?

linux - 给定一个 IP 地址,在同一子网中查找接口(interface)

linux - 从 "find"输出中删除特殊字符

linux - 识别c中的虚拟网络接口(interface)

linux - 运行脚本跳过文件

linux - Bash/Dialog 的返回值 --checklist

shell - hbase shell 命令 - 扫描和过滤

shell - Jenkins 文件 : permission denied when running sh step in Docker container

linux - 如何在 Linux 上获取/etc/ld.so.conf 中的路径列表

bash - 如何使用 makefile 压缩目录