kauer at biplane.com.au
Sun Nov 6 12:32:46 UTC 2016
On Sun, 2016-11-06 at 13:21 +0100, Ralf Mardorf wrote:
> On Sun, 06 Nov 2016 23:01:03 +1100, Karl Auer wrote:
> > On Sun, 2016-11-06 at 12:05 +0100, Ralf Mardorf wrote:
> > >
> > > [root at archlinux ~]# sudo -u rocketmouse echo $HOME
> > > /root
> > When you use a variable on the command line it is expanded before
> > the
> > command line is executed. So the above command is the equivalent
> > of:
> > sudo -u rocketmouse echo "/root"
> > >
> > > [root at archlinux ~]# sudo -u rocketmouse HOME=/home/rocketmouse
> > > echo
> > > $HOME
> > Again, $HOME is expanded before the assignment is made, so that
> > command
> > is the equivalent of:
> > sudo -u rocketmouse HOME=/home/rocketmouse echo "/root"
> > So you will need to rethink many of those tests...
> When a user runs
> sudo HOME=/root appname
> the /root directory is used.
> The home directory of "username" also is used when running
> gksudo -u username app
> so why isn't "echo $HOME" not equal to the used directory?
That's not the same as what you wrote first :-)
Let's say you are logged in as fred, and $HOME is "/home/fred".
Now you run this command:
sudo echo $HOME
What happens is that the shell expands $HOME, creating a command line
that looks like this:
sudo echo /home/fred
Then it executes sudo, passing it two arguments "echo" and
Karl Auer (kauer at biplane.com.au)
GPG fingerprint: E00D 64ED 9C6A 8605 21E0 0ED0 EE64 2BEE CBCB C38B
Old fingerprint: 3C41 82BE A9E7 99A1 B931 5AE7 7638 0147 2C3C 2AC4
More information about the ubuntu-users