I want to write a python script, that sets some shell aliases, that can be executed after running the python script.
I have tried the following approaches:
<code>import subprocess
command: str = 'alias mytest="echo test"'
subprocess.run(command, shell=True, capture_output=True, text=True)
</code>
<code>import subprocess
command: str = 'alias mytest="echo test"'
subprocess.run(command, shell=True, capture_output=True, text=True)
</code>
import subprocess
command: str = 'alias mytest="echo test"'
subprocess.run(command, shell=True, capture_output=True, text=True)
<code>import subprocess
command: str = 'alias mytest="echo test"'
subprocess.call(command, shell=True, executable='/bin/bash')
</code>
<code>import subprocess
command: str = 'alias mytest="echo test"'
subprocess.call(command, shell=True, executable='/bin/bash')
</code>
import subprocess
command: str = 'alias mytest="echo test"'
subprocess.call(command, shell=True, executable='/bin/bash')
<code>import os
command: str = 'alias mytest="echo test"'
os.system(command)
</code>
<code>import os
command: str = 'alias mytest="echo test"'
os.system(command)
</code>
import os
command: str = 'alias mytest="echo test"'
os.system(command)
<code>import os
command: str = 'alias mytest="echo test"'
os.popen(command)
</code>
<code>import os
command: str = 'alias mytest="echo test"'
os.popen(command)
</code>
import os
command: str = 'alias mytest="echo test"'
os.popen(command)
But after executing these scripts I was not able to call the alias.
I know, that I can set aliases via .bashrc
, but I have written a environment in python to manage some dynamic attributes and run processes.
Now I want to make my life a little bit easier and set some aliases to call some functionality.