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 $PATHs 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?
sudochanging the path?sudo ./test.shprints the short version so the problem has nothing to do with network namespaces. I'm still not sure how to fix it, though.ip netnsneeds privileges...man sudoerstells you all about PATH resets.