On 07/08/2014 04:42 PM, Harry Putnam wrote:
> I must be miss-understanding the usage of sudo's option `-E' (preserve users
> env).
> 
> One would think that tools found along user path would then be
> available to `sudo'
> 
> Here is what puzzles me:

[...]

> -------       -------       ---=---       -------       ------- 
> And now testing sudo -E
> -------       -------       ---=---       -------       ------- 
> 
>    harry $ sudo -E echo $PATH (filtered)
> 
>    . . . . . . . . . [...] /merb/dv/home/harry/scripts: [...] . . . . . 
> 
> 
> OK, so far sudo -E has retained the $PATH env of user `harry' that
> leads to the script in question.

As far as I can tell, sudo has _not_ retainet the $PATH, $PATH has been
replaced by it's contents in your shell and therefore the real
invocation looks like that:

        $ sudo -E echo ...:/merb/dv/home/harry/scripts:...

In other words: The variable is not resolved inside the shell started by
sudo but in your own instead.

> However, in that case I do not understand this behavior below:
> 
>   sudo -E which enw
> 
>   {no output}
> 
>   sudo -E enw
> 
>   sudo: enw: command not found

I do not understand it either. I just tried it and the ``problem'' is
reproducible: I believe it is related to some sudo policy or such. (The
manpage says ``Environment: PATH May be overriden by the security
policy.'') Also, this seems to be special to the $PATH variable. Others
work fine.

Try, for example (I have not copied this from a shell, but that is the
gist of what happens if one tests it):

$ export TEST=x
$ sudo -Es
# echo $TEST
x
# exit
$ export PATH=$PATH:test
$ echo $PATH
[...]:test
$ sudo -Es
# echo $PATH
[...]                         -- test is missing
# exit
$ echo $PATH
[...]:test

HTH
Linux-Fan

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to