连接所有参数,并用双引号将它们引起来 [英] Concatenate all arguments and wrap them with double quotes

查看:108
本文介绍了连接所有参数,并用双引号将它们引起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function foo() {
A=$@...
echo $A
}

foo bla "hello ppl"

我希望输出为:
"bla""hello ppl"

I would like the output to be:
"bla" "hello ppl"

我需要做什么而不是省略号?

What do I need to do instead of the ellipsis?

推荐答案

@msw有正确的想法(在有关问题的评论中).但是,打印带引号的参数的另一个想法是:使用printf:

@msw has the right idea (up in the comments on the question). However, another idea to print arguments with quotes: use the implicit iteration of printf:

foo() { printf '"%s" ' "$@"; echo ""; }

foo bla "hello ppl"
# => "bla" "hello ppl"

这篇关于连接所有参数,并用双引号将它们引起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆