[comp.unix.questions] Summary of Responses

shirono@hcx3.SSD.HARRIS.COM (09/03/88)

In comp.unix.questions <1000 Aug 31, 1988>, leightsu@neptune.UUCP writes:
> <...>
>
> 	su user -c shellscript
>
> <...> where is the su -c option documented. 
> It is not documented in the Ultrix and BSD4.3 doc sets that I have in 
> my possession. Am I missing something?

Yes.  -c is not an option to su.  It is an option to sh, csh, ksh (and
I believe tcsh, as well).

I don't know if Ultrix says anything about it, but sysV su has a
command line of the form

	     su [ - ] [ name [ arg ... ] ]

where [ arg ... ] are arguments passed verbatim to the shell.

______________________________________________________________________________
                               ||   Internet: shirono@ssd.harris.com
     Roberto Shironoshita      ||
      Harris Corporation       ||             ...!novavax---\
   Computer Systems Division   ||   UUCP:     ...!uunet-------!hcx1!shirono
                               ||             ...!mit-eddie-/
------------------------------------------------------------------------------
DISCLAIMER: The opinions expressed here are my own; they in no way reflect the
            opinion or policies of Harris Corporation.

jfh@rpp386.Dallas.TX.US (The Beach Bum) (09/06/88)

In article <48200005@hcx3> shirono@hcx3.SSD.HARRIS.COM writes:
>In comp.unix.questions <1000 Aug 31, 1988>, leightsu@neptune.UUCP writes:
>> It is not documented in the Ultrix and BSD4.3 doc sets that I have in 
>> my possession. Am I missing something?
>
>Yes.  -c is not an option to su.  It is an option to sh, csh, ksh (and
>I believe tcsh, as well).

the -c may not be an option to su, but it works quite nicely, thank you.


Script is typescript, started Mon Sep  5 13:01:29 1988
Subscript out of range.
1 - #rpp386-> su jfh -c id
uid=100(jfh) gid=0(root)
2 - #rpp386-> logout
Not a terminal: Not a character device
John's Words of Wisdumb -
Good leaders being scarce, following yourself is allowed.
Script done Mon Sep  5 13:01:53 1988

what most likely is happening is that -c is being passed to the shell
as the command and the command is being passed as the argument, which
the shell then interprets as a command.  so, in the end everything works
just fine.
-- 
John F. Haugh II (jfh@rpp386.Dallas.TX.US)                   HASA, "S" Division

    "If the code and the comments disagree, then both are probably wrong."
                -- Norm Schryer

gandalf@csli.STANFORD.EDU (Juergen Wagner) (09/06/88)

>In article <48200005@hcx3> shirono@hcx3.SSD.HARRIS.COM writes:
>>In comp.unix.questions <1000 Aug 31, 1988>, leightsu@neptune.UUCP writes:
>>> It is not documented in the Ultrix and BSD4.3 doc sets that I have in 
>>> my possession. Am I missing something?
>>
>>Yes.  -c is not an option to su.  It is an option to sh, csh, ksh (and
>>I believe tcsh, as well).

In article <6246@rpp386.Dallas.TX.US> jfh@rpp386.Dallas.TX.US (The Beach Bum) writes:
>...
>the -c may not be an option to su, but it works quite nicely, thank you.
>
[script deleted]
>
>what most likely is happening is that -c is being passed to the shell
>as the command and the command is being passed as the argument, which
>the shell then interprets as a command.  so, in the end everything works
>just fine.

Well, the manual for SunOS 4.0 (3.5 is the same) says:

    ...
    su [ - ] [ -f ] [ -c command ] [ username ]
    ...
    -c command
       Execute command after logging in as the new user.
    ...

Ultrix (T2.2-4A System #5) just has:

    su [ userid ]

Ok, next I tried HP-UX (HP-UX 6.0 and 5.x):

    su [ - ] [ name [ arg ... ] ]

and further down in the man page, it says:

    Any additional arguments  given  on  the  command  line  are
    passed  to  the program invoked as the shell, permitting the
    super-user  to  run   shell   procedures   with   restricted
    privileges.   When  using programs like sh(1), an arg of the
    form -c string executes string via the shell and an  arg  of
    -r will give the user a restricted shell.

4.2 BSD UNIX seems to have the -c option, too.

So far with the poll. I guess, one shouldn't rely on having it when
working under non-BSD systems (HP-UX, Ultrix).

-- 
Juergen "Gandalf" Wagner,		   gandalf@csli.stanford.edu
Center for the Study of Language and Information (CSLI), Stanford CA

shirono@hcx3.SSD.HARRIS.COM (09/09/88)

In comp.unix.questions <Sep  5, 1988 0206> jfh@rpp386.UUCP writes:
> In article <48200005@hcx3> shirono@hcx3.SSD.HARRIS.COM writes:
> >In comp.unix.questions <1000 Aug 31, 1988>, leightsu@neptune.UUCP writes:
> >> It is not documented in the Ultrix and BSD4.3 doc sets that I have in 
> >> my possession. Am I missing something?
> >
> >Yes.  -c is not an option to su.  It is an option to sh, csh, ksh (and
> >I believe tcsh, as well).
> 
> the -c may not be an option to su, but it works quite nicely, thank you.

Nobody said it wasn't.

--Roberto

guy@gorodish.Sun.COM (Guy Harris) (09/15/88)

> 4.2 BSD UNIX seems to have the -c option, too.
> 
> So far with the poll. I guess, one shouldn't rely on having it when
> working under non-BSD systems (HP-UX, Ultrix).

As most people said, the truth is:

	1) "su" doesn't have a "-c" option.  It is not in 4.2BSD, nor 4.3BSD,
	   nor SunOS, nor System V (Release 2, Release 3).

	2) UNIX shells tend to support a "-c" option, which tells them to take
	   the argument to that option and execute it as a commmand.

	3) The 4.2BSD, 4.3BSD, S5R2, and S5R3 "su" commands will pass any
	   arguments after the user name to the shell that they invoke; the
	   SunOS "su" command is derived either from the 4.2BSD or the 4.3BSD
	   version (depending on the version of SunOS), and I expect that the
	   Ultrix one is based on a 4.xBSD one and the HP-UX one is based on
	   some S5 one.

	   This is documented in the S5 man page, and that man page mentions
	   that you can use "-c" with this.  This is *not* documented in the
	   4BSD man page; the SunOS man page incorrectly states that "su" has a
	   "-c" option, rather than correctly stating that arguments after the
	   username are passed to the shell (the SunOS man page implies that
	   "su -c <command> <user>" works, but it doesn't - you have to do
	   "su <user> -c <command>").

The net result is that "su <user> -c <command>" runs the new user's shell (as
specified in the password file, with a default of "/bin/sh"), with the
arguments "-c" and "<command>".  For the shells in question (Bourne and C, and
derivatives of same such as the Korn shell and "tcsh"), this causes them to
execute the command <command>.