在sh脚本中设置ENV_VAR = $ {sh_var}

时间:2021-12-01 11:08:18

Let me preface by saying I think this is my problem. I'm not 100% sure. I'm hoping someone can tell me if I'm correct here...

让我先说我认为这是我的问题。我不是百分百肯定。我希望有人可以告诉我,如果我在这里是正确的...

I have a script I'm writing to install my go-to server stack from source in userland. Part of this script involves installing uWSGI with the PHP plugin. The part of the script in question is:

我有一个脚本,我正在编写以从userland中的源安装我的首选服务器堆栈。该脚本的一部分涉及使用PHP插件安装uWSGI。有问题的脚本部分是:

UWSGICONFIG_PHPDIR=${HOME}/php54 UWSGI_EMBED_PLUGINS=${uwsgiplugins} python2.7 uwsgiconfig.py --build

UWSGICONFIG_PHPDIR is my custom-compiled PHP installation and UWSGI_EMBED_PLUGINS is the env variable to compile uWSGI with plugins embedded in the binary. I have this set via uwsgiplugins=php at the beginning of the script.

UWSGICONFIG_PHPDIR是我自定义编译的PHP安装,UWSGI_EMBED_PLUGINS是env变量,用于编译嵌入在二进制文件中的插件的uWSGI。我在脚本的开头通过uwsgiplugins = php设置了这个集合。

When I run the script the PHP plugin is not compiled into the uWSGI binary. The best I can figure is that this is an issue with trying to pass a script variable to an env variable. If, after I run the script, I manually enter UWSGICONFIG_PHPDIR=${HOME}/php54 UWSGI_EMBED_PLUGINS=php python2.7 uwsgiconfig.py --build into the command line then the uWSGI binary compiles properly with the embedded PHP plugin.

当我运行脚本时,PHP插件不会编译到uWSGI二进制文件中。我能想到的最好的是,这是尝试将脚本变量传递给env变量的问题。如果,在我运行脚本后,我手动输入UWSGICONFIG_PHPDIR = $ {HOME} / php54 UWSGI_EMBED_PLUGINS = php python2.7 uwsgiconfig.py --build到命令行,然后uWSGI二进制文件使用嵌入式PHP插件正确编译。

Am I doing something wrong in trying to pass a variable from the sh script to an env variable on the command line? Should I be setting these variables via a different method?

我是否在尝试将变量从sh脚本传递到命令行上的env变量时做错了什么?我应该通过不同的方法设置这些变量吗?

1 个解决方案

#1


1  

Use the env command and do not forge to quote your variables:

使用env命令,不要伪造引用变量:

 env UWSGICONFIG_PHPDIR="${HOME}/php54" UWSGI_EMBED_PLUGINS="${uwsgiplugins}" python2.7 uwsgiconfig.py --build

#1


1  

Use the env command and do not forge to quote your variables:

使用env命令,不要伪造引用变量:

 env UWSGICONFIG_PHPDIR="${HOME}/php54" UWSGI_EMBED_PLUGINS="${uwsgiplugins}" python2.7 uwsgiconfig.py --build