如何使用Python 3.9永久修改Linux用户的$路径?
发行版:Debian 11
Python:3.9.2
壳:bash
我正在尝试使用Python永久更新用户的路径。我本质上想使用Python进行相当于:
export PATH="$PATH:/usr/local/bin/folderA"
export PATH="$PATH:$HOME/.local/share/folderB/bin"
echo export PATH="$PATH:$HOME/.local/bin" >> "$HOME"/.bashrc
在Python中我尝试:
import os
from pathlib import Path
dir_home = str(Path.home())
os.system('export PATH=$PATH:/usr/local/bin/folderA')
os.system('export PATH=$PATH:' + dir_home + '/.local/share/folderB/bin')
os.system('echo export PATH=$PATH:' + dir_home + '/.local/bin >>' + dir_home + '/.bashrc')
echo Export Path =“ $ path:$ home/home/.local/bin”>>> “ $ home”/。bashrc
有效,但其他两行没有输入$路径。
我不在乎它是如何完成的。我正在使用这种方法,因为我认为这是这样做的方法。
谢谢
Distro: Debian 11
Python: 3.9.2
Shell: Bash
I'm attempting to permanently update a user's path using Python. I want to essentially do the equivalent of this using Python:
export PATH="$PATH:/usr/local/bin/folderA"
export PATH="$PATH:$HOME/.local/share/folderB/bin"
echo export PATH="$PATH:$HOME/.local/bin" >> "$HOME"/.bashrc
In Python I attempted:
import os
from pathlib import Path
dir_home = str(Path.home())
os.system('export PATH=$PATH:/usr/local/bin/folderA')
os.system('export PATH=$PATH:' + dir_home + '/.local/share/folderB/bin')
os.system('echo export PATH=$PATH:' + dir_home + '/.local/bin >>' + dir_home + '/.bashrc')
The echo export PATH="$PATH:$HOME/.local/bin" >> "$HOME"/.bashrc
works but the other two lines don't get input into the $PATH.
I don't care how it gets done though. I am using this method as I thought it was the way to do it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用一个
OS.System
调用一次立即运行所有命令。Run all the commands at once with one
os.system
call.