Assume the following script:
$ cat test.sh
#!/bin/bash
echo $PATH
This happens:
$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/<user>/.local/bin:/home/<user>/bin
$ sudo ip netns exec blue echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/<user>/.local/bin:/home/<user>/bin
$ ./test.sh
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/<user>/.local/bin:/home/<user>/bin
$ sudo ip netns exec blue ./test.sh
/sbin:/bin:/usr/sbin:/usr/bin
Why. It's breaking my scripts ecosystem because it means they cannot see many of my binaries.
Out of the two distributions I've tested this in, Fedora 24 is the only one that does it. Ubuntu 14.04 echoes all $PATH
s the same as I expect.
I tried adding to the script
$ sudo ip netns exec blue PATH=$PATH
But it errors out, presumably because PATH=etcetc
is not really a command.
What is the correct way to do it?
sudo
changing the path? – derobert Sep 20 '16 at 17:41sudo ./test.sh
prints the short version so the problem has nothing to do with network namespaces. I'm still not sure how to fix it, though.ip netns
needs privileges... – Yd Ahhrk Sep 20 '16 at 17:57man sudoers
tells you all about PATH resets. – Stephen Harris Sep 20 '16 at 18:31/etc/environment
is precisely the reason why Ubuntu's sudo isn't giving me any problems. Its defaultPATH
is quite thorough while Fedora's is empty. Thanks! – Yd Ahhrk Sep 20 '16 at 20:11