Created
September 6, 2010 20:45
-
-
Save thewoolleyman/567503 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thewoolleyman: # export a=1 && eval 'sudo' '/usr/bin/env a=2 echo $a' | |
[11:26am] evalbot: thewoolleyman: bash: sudo: command not found | |
[11:26am] sn18: kolpur: because thats not positional parameter | |
[11:26am] thewoolleyman: why does that print '1' instead of '2'? | |
[11:26am] yrgd joined the chat room. | |
[11:26am] taylanub: 'foo=bar echo $foo' won't work because echo itself doesn't expand the variable | |
[11:27am] taylanub: echo has no clue of variables, the $foo gets turned into what it is in the shell's eyes | |
[11:27am] thewoolleyman: how is $a getting through the sudo whitelist then? | |
[11:27am] ampzqlox joined the chat room. | |
[11:28am] kolpur left the chat room. (Quit: Leaving) | |
[11:28am] pvl1 joined the chat room. | |
[11:28am] pragma_: what does sudo have to do with bash variables? | |
[11:31am] trash: thewoolleyman: Because your exported it. | |
[11:32am] thewoolleyman: trash: sudo has a whitelist for variables, $a shouldn't get passed through unless it is allowed in sudoers (which it isn't) | |
[11:32am] geirha: And eval expanded it | |
[11:32am] thewoolleyman: oh eval did it | |
[11:33am] karlo joined the chat room. | |
[11:33am] geirha: Neither sudo, env nor echo does anything with $var | |
[11:34am] thewoolleyman: so my goal is to get an existing variable value available in the sudo context. Is there any way to do that without hacking setenv in sudoers? | |
[11:34am] geirha: sudo env foo=bar bash -c '...' | |
[11:36am] jeff_e47 joined the chat room. | |
[11:38am] LXCC-Vincenzo left the chat room. (Quit: ChatZilla 0.9.86 [Firefox 3.6.8/20100723084720]) | |
[11:38am] thewoolleyman: geirha: sudo can't run env, it isn't a command | |
[11:39am] thewoolleyman: but you guys gave me some ideas, thanks | |
[11:39am] prince_jammys: mm | |
[11:39am] lhunath: thewoolleyman: yes, it is. | |
[11:39am] prince_jammys: SUDO_COMMAND=/usr/bin/env | |
[11:39am] prince_jammys: SUDO_USER=mischa | |
[11:39am] lhunath: # type env | |
[11:39am] evalbot: lhunath: env is /bin/env | |
[11:40am] pragma_: hey, thewoolleyman clearly has a belief system he wishes to adhere to. | |
[11:40am] karlo left the chat room. (Quit: Ex-Chat) | |
[11:40am] pragma_: Who are you to tell him what he can or can't do with env? | |
[11:40am] jetscreamer joined the chat room. | |
[11:40am] prince_jammys: we're the environmental police. | |
[11:41am] lhunath: hehe. | |
[11:41am] thewoolleyman: ok, I type: sudo '/usr/bin/env a=1 echo xxx' | |
[11:41am] thewoolleyman: and get: sudo: /usr/bin/env a=1 echo xxx: command not found | |
[11:42am] thewoolleyman: what command is it telling me isn't found? | |
[11:42am] lhunath: because that isn't a program. | |
[11:42am] pragma_: the '/usr/bin/env a=1 echo xxx' command | |
[11:42am] prince_jammys: thewoolleyman: stop quoting the whole thign | |
[11:42am] pragma_: # ls '/usr/bin/env a=1 echo xxx' | |
[11:42am] evalbot: pragma_: ls: cannot access /usr/bin/env a=1 echo xxx: No such file or directory | |
[11:42am] thewoolleyman: But is says USE MORE QUOTES a the top of the page!!! | |
[11:43am] lhunath: quotes say: "all of this is one single thing." you don't have a program in /usr/bin named "env a=1 echo xxx" | |
[11:43am] thewoolleyman: ok | |
[11:43am] lhunath: you have one named env, which takes arguemnts. | |
[11:43am] lhunath: quote the arguments (if necessary) | |
[11:43am] prince_jammys: however, echo $foo like this ain't gonna work | |
[11:44am] prince_jammys: it seems some recent-ish sudos understand sudo foo=bar command, too. | |
[11:44am] lhunath: indeed. it's important to know what the difference between a shell statement and a command invocation is. | |
[11:44am] merzo left the chat room. (Read error: Connection reset by peer) | |
[11:45am] lhunath: echo (the program in your PATH) doesn't know what '$foo' means, other than, 'dollar', 'f', 'o', 'o'. | |
[11:45am] lhunath: $foo is SHELL syntax; so give it to a shell. | |
[11:45am] lhunath: bash is a shell. so that would work: sudo env a=1 bash -c 'echo $a' | |
[11:45am] lhunath: !args > thewoolleyman | |
[11:45am] greybot: thewoolleyman: Understanding Arguments and Word Splitting: http://mywiki.wooledge.org/Arguments | |
[11:45am] pvl1 left the chat room. (Ping timeout: 245 seconds) | |
[11:46am] thewoolleyman: lhunath: ok thanks a lot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment