Question: Why doesn't -H work?

Paul M. Lambert plambert at plambert.net
Wed Oct 15 22:46:29 EDT 2003


Your asking your own shell to enter the value of $HOME.  So it does.  
And it's your home directory, not db2as's.  Because it's your shell 
doing the substitution.

I'll spell it out:

You type:

% sudo -H -u db2as echo $HOME

Your shell does subsitutions:

sudo -H -u db2as echo /home/you

Your shell splits this on words:

'sudo', '-H', '-u', 'db2as', 'echo', '/home/you'

Your shell execs sudo with all but the first word as arguments.

Sudo parses the -H and -u db2as options, becomes db2as, sets the HOME 
environment variable, and then runs:

echo /home/you

There you go.  You got exactly what you asked for!

Try:

% sudo -H -u db2as env | grep HOME=

or:

% sudo -H -u db2as sh -c 'echo $HOME'

Hope that helps!

--plambert



On Sep 29, 2003, at 1:12 PM, Malton, Craig wrote:

> Hello,
>     I'm trying to run some commands as so
>
> sudo -H -u db2as echo $HOME
>
> I'm running this as user cmalton and $HOME keeps returning as
> /home/cmalton not /export/home/db2as.  Does anyone know why -H isn't
> working for me?
>
> Thanks,
>
> Craig Malton
> IBM Senior Middleware Specialist - HP Project
> 416-410-5947
>
> ____________________________________________________________
> sudo-users mailing list <sudo-users at sudo.ws>
> For list information, options, or to unsubscribe, visit:
> http://www.sudo.ws/mailman/listinfo/sudo-users



More information about the sudo-users mailing list