Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Sep 2009 03:58:24 +0200
From:      Mel Flynn <mel.flynn+fbsd.questions@mailing.thruhere.net>
To:        freebsd-questions@freebsd.org
Subject:   Re: 'alias' + sudo
Message-ID:  <200909040358.25774.mel.flynn%2Bfbsd.questions@mailing.thruhere.net>
In-Reply-To: <20090903201036.36486533@scorpio.seibercom.net>
References:  <20090902072659.7829da56@scorpio.seibercom.net> <200909040134.05992.mel.flynn%2Bfbsd.questions@mailing.thruhere.net> <20090903201036.36486533@scorpio.seibercom.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 04 September 2009 02:10:36 Jerry wrote:
> On Fri, 4 Sep 2009 01:34:05 +0200
>
> Mel Flynn <mel.flynn+fbsd.questions@mailing.thruhere.net> wrote:
> > alias spico='/usr/local/bin/sudo pico -m' and be done with it.
>
> That is what I am currently doing; however,there are other commands
> that I want to use that are not available when used via sudo without
> modifying the alias. I did not realize that sudo had such a limitation.

It doesn't. alias has the limitation. As far as alias is concerned, a command 
is the first thing on the command line, and for good reason, as you don't want 
it to look further along the command line and attempt to expand everything.

So the shell only changes the command that is really run, when the first word 
matches an alias. Sudo or any app for that matter, never knew it was run 
through an alias.

However.....reading through the bash manpage:
If the
       last character of the alias value is a blank,  then  the  next  command
       word following the alias is also checked for alias expansion.

So.....:
$ alias sudo='/usr/local/bin/sudo '
$ alias pico='vim --version'
$ sudo pico
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul 21 2009 13:22:46)
Included patches: 1-6, 8-35, 37-48, 50-70, 73, 75-87, 90-92, 94-100, 102-137, 
139-149, 151-171, 173-190, 192-193, 195-203, 206-209

However....be aware of the consequences. If someone compromises your account, 
then setting:
alias ls='/tmp/mkroot'

and you running:
sudo ls

He just got root.
-- 
Mel



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909040358.25774.mel.flynn%2Bfbsd.questions>