[ale] Redirection using sudo...?
KingBahamut
gwosbahamut at gmail.com
Tue Jun 13 16:32:37 EDT 2006
As long as its not the desk MBT, I think youll be ok.
=)
My desk has a crack in it.
On 6/13/06, Michael B. Trausch <fd0man at gmail.com> wrote:
>
> On Tue, June 13 2006 15:15, Geoffrey wrote:
> > Michael B. Trausch wrote:
> > > Okay, so I know that the shell itself implements redirection. This is
> > > not a problem for me, as I use various forms of redirection and piping
> > > and such all the time. However, I have wondered if there is a way to
> > > change how that works.
> > >
> > > Sometimes, I want to change something in /proc or /sys. Doing
> > > something like:
> > >
> > > $ sudo echo "newvalue" > /sys/something
> >
> > Have you tried quoting the command?
> >
> > sudo 'echo "newvalue" > /sys/something'
> >
>
> That doesn't quite work because it doesn't start a subshell. I was
> looking
> at the problem from the wrong angle, due to an errant assumption on my
> part. 'sudo' handles the execution of the program itself, instead of
> using
> a subshell to do it in. Thus:
>
> fd0man at fd0man-laptop:~$ sudo 'echo fi > /fi'
> sudo: echo fi > /fi: command not found
> fd0man at fd0man-laptop:~$
>
> ... does not work because it then interprets the entire string as a
> command
> that it has to execute. You *could* have a file named that on the
> filesystem and execute it, but it would terribly bad form.
>
> Likewise, 'sudo -i' doesn't work in this way, either:
>
> fd0man at fd0man-laptop:~$ sudo -i 'echo fi > /fi'
> -bash: echo fi > /fi: No such file or directory
> fd0man at fd0man-laptop:~$
>
> However, the one way that does work is:
>
> fd0man at fd0man-laptop:~$ sudo sh -c 'echo fi > /fi'
> fd0man at fd0man-laptop:~$ cat /fi
> fi
>
> ... because you are then passing the string to bash to interpret as a
> command. Makes perfect sense now that I have seen somebody else do it --
> it made me hit myself on the head. :)
>
> - Mike
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>
>
>
--
KingBahamut
Founder of the GWoS
All Around Geek
"I could tell you the probability, but you wouldnt like it."
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ale
mailing list