I have a file name .test with a echo statement. Now I want to run this file from .bashrc file. What I have done so far is:

My .test file contains:

echo "hello everyone"

My .bashrc file contains:

echo "hello world"

Now what I want is to run .test file from .bashrc file and here is what I did

In .bashrc file

echo "hello world"
echo $ENV

Now when I try to run the .bashrc file from prompt like this

. .bashrc

I get

hello world

and errors like this


Can somebody help me please?

  • Again, you are using SPACES in the variable, just don't use trailing spaces! It should be ENV=VAR – Braiam Nov 12 '13 at 12:54

Just use:

. /path/to/.test


source /path/to/.test

Or, if you want to keep the output of . /path/to/.test in a variable ENV, then use:

ENV=$(. /path/to/.test)

So, please don't use spaces around the = in assignments.

And later, you can use $ENV variable something like:

echo $ENV
  • Thanks for the reply but you are not getting my point. I have placed one echo statement in .bashrc file and one echo statement in .test file. Now I want to display the echo statement of .test file from .bashrc file.So how can I do it? – Narwen Nov 12 '13 at 12:31
  • Exactly how I said. – Radu Rădeanu Nov 12 '13 at 12:33
  • what do you mean by that? I think you are not getting me or i am unable to explain it to you. – Narwen Nov 12 '13 at 12:35
  • @Narwen See my new edits. – Radu Rădeanu Nov 12 '13 at 12:39
  • Can you please revisit the question? I have just edited it. – Narwen Nov 12 '13 at 12:53

Your .test file is being executed as a script. Instead, you may need to fork a shell to apply the ENV variable to the shell:

$ . .bash
$ echo $ENV

My .test file has echo "something" as content and .bash has ENV=$(. /home/braiam/.test):

$ cat .bash
ENV=$(. /home/braiam/.test)
$ cat .test
echo "something"
  • No dice. When you source a file, that file doesn't need to be executable. – Radu Rădeanu Nov 12 '13 at 12:38
  • I have tried that providing executable permission but still i am getting the same result. – Narwen Nov 12 '13 at 12:40
  • @Narwen use the later part of Radu's answer, you need to fork a shell before you can source it. As you are doing it is just executing the . and .test. – Braiam Nov 12 '13 at 12:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.