Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 May 2002 16:04:19 +0100
From:      Jason Taylor <jason+freebsd@kanda.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: su and the ``-c'' option.
Message-ID:  <20020515150418.GD6657@uk2.kanda-systems.net>

next in thread | raw e-mail | index | archive | help

Forgot to cc list.

----- Forwarded message from Jason Taylor <jason+freebsd@kanda.com> -----

Date: Wed, 15 May 2002 15:57:25 +0100
From: Jason Taylor <jason+freebsd@kanda.com>
To: "Chris J. Mutter" <cjm@terminal.sil.at>
Subject: Re: su and the ``-c'' option.
Reply-To: Jason Taylor <jason+freebsd@kanda.com>
In-Reply-To: <200205141228.OAA19282@terminal.sil.at>
User-Agent: Mutt/1.3.99i

On Tue, May 14, 2002 at 02:28:51PM +0200, Chris J. Mutter wrote:
> hi,
> 
> why is the ``-c'' (execute command) option of the ``su'' needed when i want
> to execute a command as a different user? and why is this option not in the
> manpage (its only found in the EXAMPLES section of su(1)): 

Well any non - commands when presented to the shell are expected to be a script to execute.

To demonstrate this create a test script.

# echo "env" > /tmp/testscript && chmod 444 /tmp/testscript

Then try running the script from the command prompt:

# /tmp/testscript
->/tmp/testscript: Permission denied.

Obviously with no execute permission theres no way this script will run.. well not quite, try:

# /bin/sh /tmp/testscript
->@@ GIVES ENV OUTPUT@@ 

Now try:

# /usr/bin/su [someuser] /tmp/testscript

The same result..

Hopefully this should make it clear why the shells need the -c command.  This has really got nothing to do with su except that su kindly passes on all the additional arguments for the shell to process.  Remeber that these options are shell dependant and therefore should not form part of the su documentation.  Take a look at the manpage for nologin(8).  You'll notice that nologin does not accept the -c option :)

Jason

====================================================================
Jason Taylor.          Kanda Systems Ltd.     Tel: +44/0 1970 621030
Systems Manager.       Unit 17 Glanyrafon     Fax: +44/0 1970 621040
jason@kanda.com.       Enterprise Park.    Mobile: +44/0 7976 926918
http://www.kanda.com.  Ceredigion, UK          http://shop.kanda.com
====================================================================

----- End forwarded message -----

-- 
====================================================================
Jason Taylor.          Kanda Systems Ltd.     Tel: +44/0 1970 621030
Systems Manager.       Unit 17 Glanyrafon     Fax: +44/0 1970 621040
jason@kanda.com.       Enterprise Park.    Mobile: +44/0 7976 926918
http://www.kanda.com.  Ceredigion, UK          http://shop.kanda.com
====================================================================

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020515150418.GD6657>