在将列表转发到某个其他命令之前,通过某种转换(例如连接每个字符串)实质上“映射”bash参数列表的最优雅方式是什么?想起使用xargs
,但我似乎无法概念化如何做到这一点。bash:'map'函数参数?
function do_something {
# hypothetically
for arg in "[email protected]"; do
arg="$arg.txt"
done
command "[email protected]"
}
do_something file1 file2 file3
这样的结果将是致电command file1.txt file2.txt file3.txt
。
太棒了。这肯定比[本答案](http://stackoverflow.com/a/3104637/1641160)中显示的字符串操作更具可读性(和优雅) –