Gentoo Archives: gentoo-user

From: Etaoin Shrdlu <shrdlu@×××××××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] zsh and sudo
Date: Sat, 20 Feb 2010 23:01:10
Message-Id: 201002202200.08700.shrdlu@unlimitedmail.org
In Reply to: [gentoo-user] zsh and sudo by daid kahl
On Friday 19 February 2010, daid kahl wrote:
> Hello, > > I just installed zsh recently and was working on making the switch > over from bash for my daily user, provided I can get a few things > worked out. > > The biggest problem that I can't find useful results googling is zsh > interaction with sudo. > > I'm noticing some strange behavior with the PATH and also the > interpretation of '='. > > daid@flux log % sudo which useradd > which: no useradd in > (/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.4.3 > :/opt/sun-jdk-1.4.2.17/bin:/opt/sun-jdk-1.4.2.17/jre/bin:/opt/sun-jdk-1.4.2 > .17/jre/javaws:/usr/kde/3.5/bin:/usr/qt/3/bin:/usr/games/bin) daid@flux log > % sudo echo $PATH > /usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.4.3: > /opt/sun-jdk-1.4.2.17/bin:/opt/sun-jdk-1.4.2.17/jre/bin:/opt/sun-jdk-1.4.2. > 17/jre/javaws:/usr/kde/3.5/bin:/usr/qt/3/bin:/usr/games/bin:/home/daid/scri > pts:/sbin:/home/daid/.gentoo/java-config-2/current-user-vm/bin:/usr/sbin:/u > sr/local/warlock2:/usr/local/sbin:/home/daid/physics/transport_for_crib/tra > nsport1.6/bin daid@flux log % which useradd > /usr/sbin/useradd > > So sudo has the PATH set correctly, but it doesn't actually use the > correct path. Fishy!
Nope. If you do sudo echo $PATH $PATH is replaced by the calling shell before sudo even sees it, so no wonder you see the right one (btw, this should also answer your other question on why doing the same on a second instance of the shell seems to "work"). To test what path is seen when sudoing, do sudo zsh -c 'echo $PATH' that should be more accurate. But you already had an indication of what $PATH is in your first command above. This might be a good read about where to define PATH: http://zsh.sourceforge.net/FAQ/zshfaq03.html#l19
> As for interpretation of '=' I really don't understand what's > happening. It seems indiscriminate of the case in terms of mucking > about, but the exact result it not always the same. Consider the > monstrous output in the following simple case of making a new > environment variable: > > daid@flux log % sudo TEST="testing" > LESSOPEN=|lesspipe.sh %s > XDG_DATA_DIRS=/usr/local/share:/usr/kde/3.5/share:/usr/share:/usr/share > GLADE_CATALOG_PATH=: > GTK_PATH=:/usr/lib/gtk-2.0 > PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4 > .4.3:/opt/sun-jdk-1.4.2.17/bin:/opt/sun-jdk-1.4.2.17/jre/bin:/opt/sun-jdk-1 > .4.2.17/jre/javaws:/usr/kde/3.5/bin:/usr/qt/3/bin:/usr/games/bin > GDK_USE_XFT=1 > SSH_AUTH_SOCK=/tmp/ssh-mCuWxp2532/agent.2532 > USER=root >[snip] > SUDO_COMMAND=/bin/env >[snip] > TEST=testing
This looks strange, and would indeed require more investigation. For some reason, sudo is running /bin/env instead of erroring out (as no command to run has been specified). However, I doubt that has anything to do with zsh.
> Or if I want to emerge a specific package, instead I get: > > daid@flux log % sudo emerge =sudo-1.7.2_p2-r2 > zsh: sudo-1.7.2_p2-r2 not found
This is expected. See http://zsh.sourceforge.net/Doc/Release/Expansion.html#SEC78 "unsetopt EQUALS" should cure it. Unless, of course, you DO want to take advantage of zsh's special handling of "=", in which case read the documentation. Zsh is a wonderfull shell, but it does have a steep learning curve, due to its many features. Yes, you will bang your head on the wall many and many times if you don't read the documentation and continue to think in bash terms. Reading the manual (or the "user friendly" documentation) is a must. Zsh is an example of an open source project with a massive and excellent documentation, so no excuses for not reading it! :)

Replies

Subject Author
Re: [gentoo-user] zsh and sudo daid kahl <daidxor@×××××.com>