[英]References to ~ in a script break when run under sudo
I am confused about sudo and why it is doing this我对 sudo 以及它为什么这样做感到困惑
python3 -m venv ~/myvenv/env | works
sudo python3 -m venv ~/myvenv/env (command line) | works
If I then put the command python3 -m venv ~/myvenv/env
into a bash script script.sh
then I get the following results like this..如果我然后将命令python3 -m venv ~/myvenv/env
放入 bash 脚本script.sh
那么我会得到以下结果。
sudo ./script.sh | fails
./script.sh | works
I am rtying to run this command inside a bash script that needs to be launched with sudo
, anyone tell me why ti is not working?我正在尝试在需要使用sudo
启动的 bash 脚本中运行此命令,有人告诉我为什么 ti 不起作用?
When the script is run via sudo
, the ~
in the pathname is interpreted by the root shell, so it's replaced with root's home directory, not your home directory.当脚本通过sudo
运行时,路径名中的~
由根 shell 解释,因此它被替换为根的主目录,而不是您的主目录。
You should either copy the ~/myvenv
folder to root's directory, or use a full pathname to point to this environment.您应该将~/myvenv
文件夹复制到根目录,或使用完整路径名指向此环境。
python3 -m venv ~myname/myvenv/env
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.