【发布时间】:2026-02-05 21:05:02
【问题描述】:
这样的“身份”功能应满足以下两个属性:
identity $(identity a\ b c\ d)
# (Expected output:)
# a b
# c d
并且,给定以下 'argv_count' 函数:
argv_count () { echo "argv_count('$@'):$#"; }
argv_count $(identity a\ b c\ d)
# (Expected output:)
# argv_count('a b c d'):2
如果需要,可以在测试中引入额外的引号。
一个简单的候选人如以下未能通过第二次测试:
identity () { for arg in "$@"; do echo "$arg"; done; }
cat 不是正确的解决方案,因为它是相对于 stdin|stdout 的恒等函数。
【问题讨论】:
标签: bash variables arguments quotes expansion