gpt4 book ai didi

linux - 如何对父目录在 $PATH 中的 bash 脚本进行 sudo?

转载 作者:太空宇宙 更新时间:2023-11-04 10:20:58 25 4
gpt4 key购买 nike

例如

~/Desktop/scripts 位于 $PATH

cat ~/Desktop/scripts/hi

#!/bin/bash
echo hi

我试过的(当前目录是~):

hi # CLI said "hi"
sudo -E hi # sudo: hi: command not found
se hi # sudo: hi: command not found # alias se="sudo -E "

如何sudo脚本?

最佳答案

尝试以下操作:

sudo PATH="${PATH}" bash -c "hi"

解释请看man sudoers(5):

By default, the env_reset option is enabled. This causes commands to be executed with a new, minimal environment. On AIX (and Linux systems without PAM), the environment is initialized with the contents of the /etc/environment file. The new environment contains the TERM, PATH, HOME, MAIL, SHELL, LOGNAME, USER, USERNAME and SUDO_* variables in addition to variables from the invoking process permitted by the env_check and env_keep options. This is effectively a whitelist for environment variables.

关于linux - 如何对父目录在 $PATH 中的 bash 脚本进行 sudo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43931920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com