【发布时间】:2021-11-03 10:07:42
【问题描述】:
在 bash 中,我逐行解析文件并提取第一个和第二个字段,如下所示:
$ cat myfile
a1 1
a2 2
a3 3
a4
$ while read -r first second; do echo first is $first second is $second; done < myfile
first is a1 second is 1
first is a2 second is 2
first is a3 second is 3
first is a4 second is
现在,我需要将上述命令包含在bash -c 中,因为它将通过kubectl exec 执行。它没有按预期工作,只评估它在最后一行解析的内容:
$ bash -c "while read -r first second; do echo first is $first second is $second; done < myfile"
first is a4 second is
first is a4 second is
first is a4 second is
first is a4 second is
这里缺少什么?
谢谢!
【问题讨论】: