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
The secret is
sudo
,sudo matters.You can always provide the path explicitly, i.e.assuming that
rfkill
resides in/usr/sbin
, do aIn 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
This should display the PATH properly.