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?
-
1It would helpful if you could provide an example of what you are trying to do.Faheem Mitha– Faheem Mitha12/02/2015 09:48:55Commented Dec 2, 2015 at 9:48
-
you talking about environment variables? give a read at this postlese– lese12/02/2015 10:02:17Commented Dec 2, 2015 at 10:02
-
1I 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'– Gilles 'SO- stop being evil'12/02/2015 23:00:26Commented Dec 2, 2015 at 23:00
1 Answer
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.
-
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– Byte Commander12/13/2015 20:30:28Commented Dec 13, 2015 at 20:30