本文介绍了将变量传递给 vagrant 中的 shell 脚本配置器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个简单的 shell 脚本来为 vagrant 设置提供软件,如 here.

I'm using a simple shell script to provision software for a vagrant setup as seen here.

但是无法找到一种方法来获取传递给 vagrant 的命令行参数并将它们发送到外部 shell 脚本.Google 透露这是作为一项功能添加的,但我找不到任何涵盖它的文档或示例.

But can't figure out a way to take the command line arguments passed in to vagrant and send them along to an external shell script. Google reveals that this was added as a feature but I can't find any documentation covering it or examples out there.

推荐答案

你说得对.传递参数的方式是使用 :args 参数.

You're correct. The way to pass arguments is with the :args parameter.

config.vm.provision :shell, :path => "bootstrap.sh", :args => "'first arg' second"

请注意,first arg 周围的单引号仅在您希望包含空格作为传递的参数的一部分时才需要.也就是说,上面的代码相当于在终端输入以下内容:

Note that the single quotes around first arg are only needed if you want to include spaces as part of the argument passed. That is, the code above is equivalent to typing the following in the terminal:

$ bootstrap.sh 'first arg' second

脚本中 $1 指的是字符串first arg",$2 指的是字符串second".

Where within the script $1 refers to the string "first arg" and $2 refers to the string "second".

关于这个的 v2 文档可以在这里找到:http://docs.vagrantup.com/v2/provisioning/shell.html

The v2 docs on this can be found here: http://docs.vagrantup.com/v2/provisioning/shell.html

这篇关于将变量传递给 vagrant 中的 shell 脚本配置器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 14:55