ฉันจะค้นหาตัวแปรสภาพแวดล้อม SUDO_COMMAND ได้ที่ไหน


8

ปัจจุบันฉันเรียนรู้รากฐานของ Linux ด้วย Ubuntu และมีกิจกรรมเล็ก ๆ น้อย ๆ ที่ฉันต้องการค้นหาข้อมูลเกี่ยวกับตัวแปรสภาพแวดล้อม ฉันได้พบ 6/7 ข้อมูล SUDO_COMMANDแต่เพียงไม่สามารถหา นี่คือวิธีที่รายการไป:

SHELL=/bin/bash
USER=student
SUDO_COMMAND=
PWD=/home
HOME=/home/student
LOGNAME=student
OLDPWD=/home/student 

ฉันสังเกตเห็นว่าข้อมูลมาตามลำดับและSUDO_COMMANDอยู่ระหว่างผู้ใช้และ pwd ฉันทำผิดพลาดที่ไหนสักแห่งหรือไม่?


1
คุณมีสิทธิ์ sudo ไหม
ravery

คำตอบ:


11

SUDO_COMMANDเป็นตัวแปรสภาพแวดล้อมที่กำหนดโดยsudoเฉพาะในสภาพแวดล้อมของกระบวนการที่เริ่มต้นโดยมัน (และสืบทอดโดยกระบวนการลูกใด ๆ ) หากคุณทำงานsudo some-command arg1 arg2แล้วSUDO_COMMANDจะมีเส้นทางที่แน่นอนและsome-command arg1 arg2หากคุณวิ่งsudo -sหรือsudo -iตัวแปรจะถูกตั้งเป็นเชลล์ที่เริ่มทำงาน ในกรณีใด ๆ sudoที่คุณอาจจะไม่เห็นมันนอกของต้นไม้กระบวนการที่ตั้งขึ้นโดย

ตัวอย่างเช่น:

$ sudo sh -c 'echo $SUDO_COMMAND'
/bin/sh -c echo $SUDO_COMMAND

หรือ:

$ sudo env
HOME=/home/muru
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
TERM=xterm-256color
LANG=en_US.UTF-8
LC_NUMERIC=en_GB.UTF-8
LC_TIME=en_GB.UTF-8
LC_MONETARY=en_GB.UTF-8
LC_PAPER=en_GB.UTF-8
LC_NAME=en_GB.UTF-8
LC_ADDRESS=en_GB.UTF-8
LC_TELEPHONE=en_GB.UTF-8
LC_MEASUREMENT=en_GB.UTF-8
LC_IDENTIFICATION=en_GB.UTF-8
MAIL=/var/mail/root
LOGNAME=root
USER=root
USERNAME=root
SHELL=/bin/bash
SUDO_COMMAND=/usr/bin/env
SUDO_USER=muru
SUDO_UID=1000
SUDO_GID=1000

ฉันสังเกตเห็นว่าข้อมูลมาในลำดับ

ผมไม่ทราบว่าคำสั่งที่คุณใช้ แต่คุณไม่สามารถพึ่งพาการส่งออกของset, declare, envหรือprintenvจะเป็นในการสั่งซื้อบางส่วน


และฉันคิดว่าsudo echo $SUDO_COMMANDสามารถใช้เพื่อสร้างวง infinitive … :(
ของหวาน

5

SUDO_COMMANDเป็นตัวแปรสภาพแวดล้อมซึ่งชุดคำสั่งที่ดำเนินการโดย sudo

ตามที่กล่าวถึงโดย @muru - หากsudoเรียกใช้เชลล์ใหม่ - ตัวแปรสภาพแวดล้อมนี้จะแสดงในเชลล์ใหม่นี้

ข้อมูลเพิ่มเติม

man sudo ให้รายละเอียดดังต่อไปนี้:

ENVIRONMENT
 sudo utilizes the following environment variables.  The security policy
 has control over the actual content of the command's environment.

 EDITOR           Default editor to use in -e (sudoedit) mode if neither
                  SUDO_EDITOR nor VISUAL is set.

 MAIL             Set to the mail spool of the target user when the -i
                  option is specified or when env_reset is enabled in
                  sudoers (unless MAIL is present in the env_keep list).

 HOME             Set to the home directory of the target user when the -i
                  or -H options are specified, when the -s option is
                  specified and set_home is set in sudoers, when
                  always_set_home is enabled in sudoers, or when env_reset
                  is enabled in sudoers and HOME is not present in the
                  env_keep list.

 LOGNAME          Set to the login name of the target user when the -i
                  option is specified, when the set_logname option is
                  enabled in sudoers or when the env_reset option is
                  enabled in sudoers (unless LOGNAME is present in the
                  env_keep list).

 PATH             May be overridden by the security policy.

 SHELL            Used to determine shell to run with -s option.

 SUDO_ASKPASS     Specifies the path to a helper program used to read the
                  password if no terminal is available or if the -A option
                  is specified.

 SUDO_COMMAND     Set to the command run by sudo.

ฉันไม่คิดว่าตัวอย่างของคุณทำซ้ำได้จริง SUDO_COMMANDเพียง แต่อยู่ในสภาพแวดล้อมที่ตั้งขึ้นโดยsudoถ้าSUDO_COMMANDจริงที่แล้วคุณจะไม่ได้รับเปลือกวิ่ง/bin/ls echo $SUDO_COMMAND
muru
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.