[Wine] Problems with wincfg

Martin Gregorie martin at gregorie.org
Tue Jun 19 14:42:57 CDT 2012

On Tue, 2012-06-19 at 13:59 -0500, David Bailey wrote:
> I'm having difficulty getting my password back for the bugs website, but I wanted to add that testing for USER == root doesn't seem to handle sudo:
> sudo echo $USER
> returns 'dave' for me.
This depends on when $USER is evaluated and (in a bash session) when the 
value is substituted for the variable name. In your example substitution 
will occur when bash parses the command line, i.e. 'dave' was substituted 
for $USER before sudo was executed. OTOH, if the substitution done is inside
a simple script which is run under the control of sudo, then the substitution 
takes place within the environment established by sudo. Here you go:

$ cat test
echo $USER
$ ./test
$ sudo ./test

What happens is that this time no substitution happens when the command
is parsed. Instead, sudo changes user to root and spawns a shell under
that user. This shell executes the script by spawning a second shell (by
executing #!/bin/bash as 'root') and this evaluates $USER and does the

Of course, much the same applies if the value of USER is retrieved
within a C program by calling getenv(): again, its a delayed evaluation
that would happen after sudo has done its thing. Finally, take a look at
the next version of my script and think about what it does:

$ cat ./test
if [ -n "$1" ]
	echo $1
	echo $USER
echo "Local USER is $USER"
$ sudo ./test $USER
Local USER is root
$ sudo ./test 
Local USER is root


More information about the wine-users mailing list