So I've been trying to modify
.bash_aliases programatically for a while now, and I've been running into issues with every method I've tried.
sudo python3 myscript.pycauses the script to modify the
.bash_aliasesfile of the
rootuser. I can't find a way to determine what user ran the script to modify their file.
sudo echo "my string" >> ~/.bash_aliasesgets an error:
sh: 1: cannot create /home/migue/.bash_aliases: Permission denied, presumably because sudo can't display its password prompt when I call it programatically.
~) of the file.
Basically, I'd love to know any reasonable method to modify and append to
.bash_aliases through a Python script. I haven't found any questions on this where the solutions worked for me.
I'd prefer for this method to not require any non-standard modules, as installing them will just make the process less seamless for people who use the script.
I can't find a way to determine what user ran the script to modify their file.
You can reference the file
~/.bash_aliases in your script and run it without sudo, unless your current user is root.
You simply need to add write privileges to
.bash_aliases for every user it belongs to.
Admin | 1 month ago