Subject: Re: su '-c'
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: tech-userlevel
Date: 05/01/2003 15:28:07
[ On Thursday, May 1, 2003 at 11:12:26 (-0700), Greywolf wrote: ]
> Subject: Re: script command
>
> [note that quotes are needed around "command args..." in order to get
> it to work properly.]

No, not really.  To use sed syntax on argv in place of the pointer
arithmetic used in the code:

	s/su username/sh/

and then call exec()!  :-)

Note that something like "sh -c 'echo hello world'" does indeed require
the quotes, but that's because of the way "sh -c foo" works, not because
of how "su user -c foo".  You can pass other args to "sh" from "su",
like this:

	# su root -v -x -c 'echo hello there'
	+ echo hello there
	hello there
	# 

> Regarding su:  Since 'su' with no args denotes 'su root', should not
> "su -c 'command args...'" execute "command args"?  Perhaps that's
> not the way it's ever worked, but it would seem to make the most sense.
> Otherwise we should *gag choke* _require_ a username and not assume
> a default -- or does that break other things (like user habits and
> POS-ix compliance)?

Well, to be nice and POSIXy, it maybe should (have) be(en):

	su [-lm] [-u username] [-C class] [shell-args ...]

but with old-hand unix-types being so averse to typing anything more
than they think they actually really have to type (for good reason, as
you will know if you've ever pounded on an ASR-33), the '-u' was left
out and the rest is history....

> I just R'd TFM and I note that we have added [ -c login-class ] to the
> syntax.  Should that have been better thought out and done as -C?

well, perhaps, but the culprit is probably BSDi, or maybe FreeBSD, where
this "login class" stuff came from in the first place:

     su [-] [-Kflm] [-c class] [login [args ...]]

Since 'su' is little used in scripts, and not specified by POSIX, I've a
good mind to change my version.....

-- 
								Greg A. Woods

+1 416 218-0098;            <g.a.woods@ieee.org>;           <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>