bash导出命令 [英] bash export command

查看:125
本文介绍了bash导出命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在导出命令上,我的64位Ubuntu遇到了一个奇怪的问题.

I am encountering a strange problem with my 64bit Ubuntu - on the export command.

基本上,我在Win7上的Ubuntu上安装了VM,我正尝试使用自定义(由客户端提供)软件将命令从Windows传递到VM安装.

Basically, I have got a VM installation on Ubuntu on my Win7, and I am trying to pass commands from my windows to my VM installation using a custom (given by client) software.

因此,在我的VM上,当我这样做时:

So, on my VM, when I do:

export foo=bar
echo $foo

一切正常.

但是,当我通过自定义软件(基本上将linux命令作为字符串传递给bash shell)进行操作时,我得到:

However, when I do the same through the custom software (which basically passes the linux command as a string to the bash shell), I get:

export: command not found

我尝试使用以下方法查看外壳(使用自定义软件)

I tried looking at the shell (using the custom software), using:

echo $SHELL>shell.txt

我得到了预期的/bin/bash,但仍然得到export:命令未找到错误.

and I get /bin/bash which is expected and I still get the export: command not found error.

我想知道以前是否有人见过这个错误?

I was wondering if anyone had seen this error before?

推荐答案

export是Bash内置的,echo$PATH中的可执行文件.因此Bash会按原样解释export,而不会产生新的进程.

export is a Bash builtin, echo is an executable in your $PATH. So export is interpreted by Bash as is, without spawning a new process.

您需要让Bash解释您的命令,您可以使用-c选项将其作为字符串传递:

You need to get Bash to interpret your command, which you can pass as a string with the -c option:

bash -c "export foo=bar; echo \$foo"

也:

bash -c的每次调用均从一个全新的环境开始.像这样:

Each invocation of bash -c starts with a fresh environment. So something like:

bash -c "export foo=bar"
bash -c "echo \$foo"

将不起作用.第二次调用不记得foo.

will not work. The second invocation does not remember foo.

相反,您需要在bash -c的单次调用中链接由;分隔的命令:

Instead, you need to chain commands separated by ; in a single invocation of bash -c:

bash -c "export foo=bar; echo \$foo"

这篇关于bash导出命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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