I basically want to set path for some of the variables in Unix. But the source command does not work here. Any suggestions of the same?

  • 1
    It would helpful if you could provide an example of what you are trying to do. – Faheem Mitha Dec 2 '15 at 9:48
  • you talking about environment variables? give a read at this post – lese Dec 2 '15 at 10:02
  • 1
    I understand that you're using Python. I think you're trying to use a bash command in Python. That obviously doesn't work since bash and python are different languages. But I don't understand what you're trying to do. Post your code, and explain what you want it to do. – Gilles 'SO- stop being evil' Dec 2 '15 at 23:00

I tried what you describe and the solution is to use . instead of source, which is basically an alias of the former.
You also must explicitly specify ./FILENAME if the file in the current directory.

Please see my example session:

Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system("source .bashrc")
sh: 1: source: not found
>>> os.system(". .bash_aliases")
sh: 1: .: .bash_aliases: not found
>>> os.system(". ./.bash_aliases")
>>> os.system(". ~/.bash_aliases")
>>> os.system(". /home/USERNAME/.bash_aliases")

A return value of 0 indicates success.

However, I am not sure if sourcing a file this way produces the results you want, as this method runs the given command in a subshell and I am not sure if this also affects the shell session you want.

  • 2
    @MikhileshSekhar Instead of writing "Thank you!" comments, please click the grey tick button on the left of this answer to accept it. Make sure you have read the short info What should I do when someone answers my question? and have checked out the tour page to learn the most important stuff about how this site works. Thanks! :-) – Byte Commander Dec 13 '15 at 20:30

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