skip to Main Content

The PATH environment variable:

debian@debian:~$ echo  $PATH
/home/debian/.local/bin:/home/debian/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

We can see that /usr/sbin is not in the $PATH.
Execute a command:

sudo strace bash -c 'sudo rfkill unblock wlan'  2>&1 | grep  rfkill

The calls are traced as below:

execve("/usr/bin/bash", ["bash", "-c", "sudo rfkill unblock wlan"], 0x7ffc8af3afd0 /* 17 vars */) = 0
execve("/usr/bin/sudo", ["sudo", "rfkill", "unblock", "wlan"], 0x55ba46abfa50 /* 20 vars */) = 0
stat("/usr/local/sbin/rfkill", 0x55f5cf165f80) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/rfkill", 0x55f5cf165f80) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/rfkill", {st_mode=S_IFREG|0755, st_size=47184, ...}) = 0

rfkill is called in the /usr/sbin/rfkill. Why is command /usr/sbin/rfkill called when /usr/sbin is not in $PATH?

2

Answers


  1. Chosen as BEST ANSWER

    The secret is sudo,sudo matters.

    cat  /etc/sudoers | rg path
    Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    

  2. You can always provide the path explicitly, i.e.assuming that rfkill resides in /usr/sbin, do a

    sudo strace bash -c 'sudo /usr/sbin/rfkill unblock wlan'  2>&1 | grep  rfkill
    

    In your case, it seems to be in the PATH, but you don’t query the PATH correctly, so you can’t see it. Try a

    sudo bash -c 'printenv PATH; type -a rfkill'
    

    This should display the PATH properly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search