像所有的命令行参数bash脚本存储到一个变量 [英] Like to store all command-line arguments to a bash script into a single variable

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

问题描述

让我们说我有一个叫bash脚本的 foo.sh

我想这样称呼它

  foo.sh这里的东西在命令行一堆

和我想它所有的文本存储到一个变量并打印出来。

所以,我的输出是:

 下面是在命令行一堆东西

我将如何做到这一点?


解决方案

 回声$ *

会做你想做的,即打印出完整的命令行参数,用空格隔开(或者,在技术上,无论 $ IFS 的值)。如果你想将它存储到一个变量,你可以做

  thevar =$ *

如果不回答你的问题不够好,我不知道该说些什么......

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

I'd like to call it like this

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.

So my output would be:

Here is a bunch of stuff on the command-line

How would I do this?

解决方案

echo "$*"

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脚本存储到一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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