[ale] Redirection using sudo...?
Michael B. Trausch
fd0man at gmail.com
Tue Jun 13 16:23:02 EDT 2006
On Tue, June 13 2006 15:19, KingBahamut wrote:
> On 6/13/06, Pat Regan <thehead at patshead.com> wrote:
> > Michael B. Trausch wrote:
> > > Nope. The following were tried, and failed. :-/
> > >
> > > fd0man at fd0man-laptop:~$ sudo -i (echo 1 > /file)
> > > bash: syntax error near unexpected token `('
> > > fd0man at fd0man-laptop:~$ sudo -i echo 1 > /file
> > > bash: /file: Permission denied
> > > fd0man at fd0man-laptop:~$ sudo sh -c { echo 1 > /file }
> > > bash: /file: Permission denied
> > > fd0man at fd0man-laptop:~$
> >
> > This works for me:
> >
> > sudo sh -c 'echo 1 > /root/file'
> >
>
> odd.....whats different.....methinks...
>
It makes sense to me, now that I have seen it. I simply wasn't putting my
knowledge together. :-)
sh -c runs a command in a subshell (e.g., spawns another shell process).
The single quote characters tell the shell you are typing into to not
escape or interpret anything within them, to pass the string literally as a
parameter. So the subshell sees everything between them, and it (instead
of the parent shell) interprets the redirection operator.
- Mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
More information about the Ale
mailing list