本文介绍了我想将Bash脚本的所有命令行参数存储到单个变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为 foo.sh 的Bash脚本.

Let's say I have a Bash script called foo.sh.

我想这样称呼它:

foo.sh Here is a bunch of stuff on the command-line

我希望将所有文本存储到单个变量中并打印出来.

And I'd like it to store all of that text into a single variable and print it out.

所以我的输出是:

Here is a bunch of stuff on the command-line

我该怎么做?

推荐答案

echo "$*"

将做您想要的事情,即打印出整个命令行参数,并用空格分隔(或者,从技术上讲,无论$IFS的值是多少).如果要将其存储到变量中,可以这样做

would do what you want, namely printing out the entire command-line arguments, separated by a space (or, technically, whatever the value of $IFS is). If you wanted to store it into a variable, you could do

thevar="$*"

如果这还不能很好地回答您的问题,我不确定还有什么要说的...

If that doesn't answer your question well enough, I'm not sure what else to say...

这篇关于我想将Bash脚本的所有命令行参数存储到单个变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 20:10