1 |
On Friday 19 February 2010, daid kahl wrote: |
2 |
> Hello, |
3 |
> |
4 |
> I just installed zsh recently and was working on making the switch |
5 |
> over from bash for my daily user, provided I can get a few things |
6 |
> worked out. |
7 |
> |
8 |
> The biggest problem that I can't find useful results googling is zsh |
9 |
> interaction with sudo. |
10 |
> |
11 |
> I'm noticing some strange behavior with the PATH and also the |
12 |
> interpretation of '='. |
13 |
> |
14 |
> daid@flux log % sudo which useradd |
15 |
> which: no useradd in |
16 |
> (/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.4.3 |
17 |
> :/opt/sun-jdk-1.4.2.17/bin:/opt/sun-jdk-1.4.2.17/jre/bin:/opt/sun-jdk-1.4.2 |
18 |
> .17/jre/javaws:/usr/kde/3.5/bin:/usr/qt/3/bin:/usr/games/bin) daid@flux log |
19 |
> % sudo echo $PATH |
20 |
> /usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.4.3: |
21 |
> /opt/sun-jdk-1.4.2.17/bin:/opt/sun-jdk-1.4.2.17/jre/bin:/opt/sun-jdk-1.4.2. |
22 |
> 17/jre/javaws:/usr/kde/3.5/bin:/usr/qt/3/bin:/usr/games/bin:/home/daid/scri |
23 |
> pts:/sbin:/home/daid/.gentoo/java-config-2/current-user-vm/bin:/usr/sbin:/u |
24 |
> sr/local/warlock2:/usr/local/sbin:/home/daid/physics/transport_for_crib/tra |
25 |
> nsport1.6/bin daid@flux log % which useradd |
26 |
> /usr/sbin/useradd |
27 |
> |
28 |
> So sudo has the PATH set correctly, but it doesn't actually use the |
29 |
> correct path. Fishy! |
30 |
|
31 |
Nope. If you do |
32 |
|
33 |
sudo echo $PATH |
34 |
|
35 |
$PATH is replaced by the calling shell before sudo even sees it, so no wonder |
36 |
you see the right one (btw, this should also answer your other question on why |
37 |
doing the same on a second instance of the shell seems to "work"). |
38 |
To test what path is seen when sudoing, do |
39 |
|
40 |
sudo zsh -c 'echo $PATH' |
41 |
|
42 |
that should be more accurate. But you already had an indication of what $PATH |
43 |
is in your first command above. |
44 |
|
45 |
This might be a good read about where to define PATH: |
46 |
|
47 |
http://zsh.sourceforge.net/FAQ/zshfaq03.html#l19 |
48 |
|
49 |
> As for interpretation of '=' I really don't understand what's |
50 |
> happening. It seems indiscriminate of the case in terms of mucking |
51 |
> about, but the exact result it not always the same. Consider the |
52 |
> monstrous output in the following simple case of making a new |
53 |
> environment variable: |
54 |
> |
55 |
> daid@flux log % sudo TEST="testing" |
56 |
> LESSOPEN=|lesspipe.sh %s |
57 |
> XDG_DATA_DIRS=/usr/local/share:/usr/kde/3.5/share:/usr/share:/usr/share |
58 |
> GLADE_CATALOG_PATH=: |
59 |
> GTK_PATH=:/usr/lib/gtk-2.0 |
60 |
> PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4 |
61 |
> .4.3:/opt/sun-jdk-1.4.2.17/bin:/opt/sun-jdk-1.4.2.17/jre/bin:/opt/sun-jdk-1 |
62 |
> .4.2.17/jre/javaws:/usr/kde/3.5/bin:/usr/qt/3/bin:/usr/games/bin |
63 |
> GDK_USE_XFT=1 |
64 |
> SSH_AUTH_SOCK=/tmp/ssh-mCuWxp2532/agent.2532 |
65 |
> USER=root |
66 |
>[snip] |
67 |
> SUDO_COMMAND=/bin/env |
68 |
>[snip] |
69 |
> TEST=testing |
70 |
|
71 |
This looks strange, and would indeed require more investigation. For some |
72 |
reason, sudo is running /bin/env instead of erroring out (as no command to run |
73 |
has been specified). However, I doubt that has anything to do with zsh. |
74 |
|
75 |
> Or if I want to emerge a specific package, instead I get: |
76 |
> |
77 |
> daid@flux log % sudo emerge =sudo-1.7.2_p2-r2 |
78 |
> zsh: sudo-1.7.2_p2-r2 not found |
79 |
|
80 |
This is expected. See |
81 |
|
82 |
http://zsh.sourceforge.net/Doc/Release/Expansion.html#SEC78 |
83 |
|
84 |
"unsetopt EQUALS" |
85 |
|
86 |
should cure it. Unless, of course, you DO want to take advantage of zsh's |
87 |
special handling of "=", in which case read the documentation. |
88 |
|
89 |
|
90 |
Zsh is a wonderfull shell, but it does have a steep learning curve, due to its |
91 |
many features. Yes, you will bang your head on the wall many and many times if |
92 |
you don't read the documentation and continue to think in bash terms. |
93 |
Reading the manual (or the "user friendly" documentation) is a must. Zsh is an |
94 |
example of an open source project with a massive and excellent documentation, |
95 |
so no excuses for not reading it! :) |