Linux bash 导出命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10108950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:43:44  来源:igfitidea点击:

bash export command

linuxubuntu

提问by JohnJ

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

我的 64 位 Ubuntu 遇到了一个奇怪的问题 - 在 export 命令上。

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.

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

So, on my VM, when I do:

所以,在我的虚拟机上,当我这样做时:

export foo=bar
echo $foo

everything works as expected.

一切都按预期工作。

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:

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

export: command not found

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

我尝试查看外壳(使用自定义软件),使用:

echo $SHELL>shell.txt

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

我得到了预期的 /bin/bash 并且我仍然得到 export: command not found 错误。

I was wondering if anyone had seen this error before?

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

采纳答案by ArjunShankar

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

export是 Bash 内置程序,echo是您的$PATH. 所以export被 Bash 按原样解释,没有产生新的进程。

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

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

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

ALSO:

还:

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

每次调用都bash -c从一个全新的环境开始。所以像:

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

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

不管用。第二次调用不记得了foo

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

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

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

回答by Vincent L.

Are you certain that the software (and not yourself, since your test actually only shows the shell used as default for your user) uses /bin/bash ?

您确定该软件(而不是您自己,因为您的测试实际上仅显示用作用户默认值的 shell)使用 /bin/bash 吗?

回答by theglauber

Probably because it's trying to execute "export" as an external command, and it's a shell internal.

可能是因为它试图将“导出”作为外部命令执行,并且它是内部的 shell。

回答by bukzor

SHELLis an environment variable, and so it's not the most reliable for what you're trying to figure out. If your tool is using a shell which doesn't set it, it will retain its old value.

SHELL是一个环境变量,因此对于您要弄清楚的内容来说,它并不是最可靠的。如果您的工具使用的外壳没有设置它,它将保留其旧值。

Use psto figure out what's really going on.

使用ps搞清楚到底发生了什么上。

回答by lwpro2

change from bash to sh scripting, make my script work.

从 bash 更改为 sh 脚本,使我的脚本工作。

!/bin/sh

!/bin/sh

回答by karuna

If you are using C shell -

如果您使用的是 C shell -

setenv PATH $PATH":/home/tmp"

回答by Hasee Amarathunga

Follow These step to Remove " bash export command not found." Terminal open error fix>>>>>>

按照这些步骤删除“找不到 bash 导出命令”。终端打开错误修复>>>>>>

open terminal and type : root@someone:~# nano ~/.bashrc

打开终端并输入:root@someone:~# nano ~/.bashrc

After Loading nano: remove the all 'export PATH = ...........................' lines and press ctrl+o to save file and press ctrl+e to exit.

加载 nano 后:删除所有 'export PATH = .........................' 行并按 ctrl+o 保存文件并按ctrl+e 退出。

Now the Terminal opening error will be fixed.........

现在终端打开错误将被修复.........

回答by anand kakaraddi

if u cant use " export " cmd
then Just use:

如果你不能使用“export”cmd,
那么只需使用:

setenv path /dir

like this

像这样

setenv ORACLE_HOME /data/u01/apps/oracle/11.2.0.3.0