这是一个纯粹的美学问题,因为我现在有一个工作命令,但我想wc -m
在没有显式循环或运行子 shell/子 shell 进程的情况下针对我的客户端数组中的每个元素运行。Bash 是在 macOS 上运行的 v5.0.18。
clients=(one two three)
printf '%s\n' "${clients[@]}" | xargs -I{} bash -c 'echo -n {} | wc -m' | sort -nr | head -1
经过更多的谷歌搜索,我发现了这段不错的 awk 脚本:
printf '%s\n' "${clients[@]}" | awk '{print length}' | sort -nr | head -1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句