public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Etaoin Shrdlu <shrdlu@unlimitedmail.org>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] zsh and sudo
Date: Sat, 20 Feb 2010 22:00:08 +0000	[thread overview]
Message-ID: <201002202200.08700.shrdlu@unlimitedmail.org> (raw)
In-Reply-To: <3ac129341002181733m4af5bea0j53e67fcd09100470@mail.gmail.com>

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! :)



  parent reply	other threads:[~2010-02-20 23:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-19  1:33 [gentoo-user] zsh and sudo daid kahl
2010-02-19 13:07 ` Helmut Jarausch
2010-02-20 22:00 ` Etaoin Shrdlu [this message]
2010-02-21 16:33   ` daid kahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201002202200.08700.shrdlu@unlimitedmail.org \
    --to=shrdlu@unlimitedmail.org \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox