Bash Export Command

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

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

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:

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".

How can I fix this?

10

8 Answers

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.

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"

ALSO:

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

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

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

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

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

If you are using C shell -

setenv PATH $PATH":/home/tmp"

If you can’t use the "export" command then just use:

setenv path /dir

Like this

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

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

SHELL is 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.

Use ps to figure out what's really going on.

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?

Changing from Bash to sh scripting made my script work:

!/bin/sh
1

Follow these steps to remove "bash export command not found." Terminal open error fix>>>>>>

Open a terminal and type:

nano ~/.bashrc

After loading nano:

Remove the all 'export PATH = ...' lines and press Ctrl + O to save file and press Ctrl + E to exit.

Now the terminal opening error will be fixed...

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest