I currently have an automated process that allows me to run a python script to be able to edit the .bashrc file in my vagrant box.
The code looks like this:
if 'THIS STRING' not in open('/home/vagrant/.bashrc').read():
with open("/home/vagrant/.bashrc", "a") as bash:
bash.write('THIS STRING')
execfile("/home/vagrant/.bashrc")
The code THIS STRING exists in the .bashrc and if it doesnt, it should open it, add it in there and source the file.
To source the file, i thought i would use the execfile function in python. This can definitely be done just by sourcing it manually;
$ sudo source /home/vagrant/.bashrc
However, i am getting an error message stating the following;
Traceback (most recent call last):
File "/var/www/soething.py", line 233, in <module>
execfile("/home/vagrant/.bashrc")
File "<string>", line 6
case $- in
The error message is targeting the execfile every single time.
I have also tried the following;
exec(open("/home/vagrant/.bashrc").read())
Still the same error - Any thoughts on why this error or what i am doing wrong?