Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

closed as unclear what you're asking by Gilles, mdpc, Scott, dhag, cas Dec 3 '15 at 5:23

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

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  
What have you tried? What happens? What do you expect to happen? – DopeGhoti Dec 2 '15 at 11:28
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 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
32512
>>> os.system(". .bash_aliases")
sh: 1: .: .bash_aliases: not found
512
>>> os.system(". ./.bash_aliases")
0
>>> os.system(". ~/.bash_aliases")
0
>>> os.system(". /home/USERNAME/.bash_aliases")
0

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.

share|improve this answer
    
Thank you so much for the update.... – Mikhilesh Sekhar Dec 13 '15 at 18:20
    
@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.