From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1NiyJx-0003HS-VI for garchives@archives.gentoo.org; Sat, 20 Feb 2010 23:01:10 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 105EBE08A5; Sat, 20 Feb 2010 23:00:49 +0000 (UTC) Received: from dcnode-02.unlimitedmail.net (smtp.unlimitedmail.net [94.127.184.242]) by pigeon.gentoo.org (Postfix) with ESMTP id D00D0E08A5 for ; Sat, 20 Feb 2010 23:00:48 +0000 (UTC) Received: from scooter.localnet (102.88.187.81.in-addr.arpa [81.187.88.102]) (authenticated bits=0) by dcnode-02.unlimitedmail.net (8.14.3/8.14.3) with ESMTP id o1KM85FA024149 for ; Sat, 20 Feb 2010 23:08:05 +0100 From: Etaoin Shrdlu To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] zsh and sudo Date: Sat, 20 Feb 2010 22:00:08 +0000 User-Agent: KMail/1.12.3 (Linux/2.6.31-gentoo-r6; KDE/4.3.3; x86_64; ; ) References: <3ac129341002181733m4af5bea0j53e67fcd09100470@mail.gmail.com> In-Reply-To: <3ac129341002181733m4af5bea0j53e67fcd09100470@mail.gmail.com> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201002202200.08700.shrdlu@unlimitedmail.org> X-UnlimitedMail-MailScanner-From: shrdlu@unlimitedmail.org X-Spam-Status: No X-Archives-Salt: 319f173d-973d-43f8-8fb4-b5ef4b8d647f X-Archives-Hash: 435158b3c802e4348e52c20669b16050 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! :)