【发布时间】:2020-05-21 23:25:20
【问题描述】:
我有以下命令序列来检查目录中的 JSON 文件:
npm install --global --no-save jsonlint-cli
FILES="$(find . -name '*.json' -type f -print)"
echo -e "Discovered JSON files:\n$FILES"
echo "$FILES" | tr '\n' ' ' | xargs jsonlint-cli
我完全意识到这是一个 NO-NO,因为它不使用 -print0 | xargs -0 模式。
但是,我想保留回显已发现文件的能力,但也只调用一次 find 和 jsonlint-cli。
ash can't store \0 in a variable.所以这将不工作:
FILES="$(find . -name '*.json' -type f -print0)"
echo -e "Discovered JSON files:\n$FILES" | tr '\0' '\n' # No effect, '\0' already gone
echo "$FILES" | xargs -0 jsonlint-cli
我怎样才能使用-print0 | xargs -0 仍然保持将发现的文件回显到标准输出的当前行为?
本例中的外壳是ash(在node:alpine Docker 容器内)。
【问题讨论】:
-
值得一提的是ash does not support process substitution / 将标准输出发送到多个命令