33

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
  • 9
    export isn't a real command (i.e. not in /bin, /usr/bin etc.) it's handled by bash internally. You could do bash -c "export foo=bar;echo \$foo" if you wanted to... Commented Apr 11, 2012 at 15:23
  • What is this custom software you speak of? Commented Apr 11, 2012 at 15:23
  • 1
    What Adam says might be the key to your problem. export is a bash builtin. echo is a binary that resides in your $PATH Commented Apr 11, 2012 at 15:24
  • What is the 'custom (given by client)' software? Commented Apr 11, 2012 at 15:25
  • Thanks you guys for your response. The "custom software" is a bunch of java code my client has written, and it contains a feature to run linux commands (basically passes the commands as a string to shell). I will try the bash -c option and update you guys with the result. Commented Apr 11, 2012 at 15:28

8 Answers 8

39

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"
Sign up to request clarification or add additional context in comments.

4 Comments

The "ALSO" paragraph helped me solve my problem. Thanks
I executed $ bash -c "export foo=bar", but it says $ bash -c "echo \$foo" foo: Undefined variable.
This does not overwrite the value on my centos 5.11, the echo in this line still prints the old value
@DavidDunham there are two snippets in the answer: The first one calls export and echo in one bash invocation and the other in two separate ones. Accordingly, the first one should "overwrite" the variable (although only temporarily, and then print the new value) and the second should not. What did you observe?
6

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

Comments

5

If you are using C shell -

setenv PATH $PATH":/home/tmp"

Comments

1

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

Comments

1

Changing from Bash to sh scripting made my script work:

!/bin/sh

1 Comment

actually you were right as well. sometimes the default shell is not either bash or sh, using this command fixes the issue
0

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.

Comments

0

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?

Comments

-3

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 Comment

'export PATH Files in the borrom of the file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.