From: Sthu Deus on
Good day.

The following:

$ su -c 'abc' -l anotheruser

but it returns

-su: abc: command not found

The abc is in the anotheruser's path, but it seems option '-l' does not
work here.

How I can accomplish the goal (without manually specifying complete
path)?


Thank You for Your time.


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4c359a04.487e0e0a.4c8c.7106(a)mx.google.com
From: Bob McGowan on
On 07/08/2010 02:27 AM, Sthu Deus wrote:
> Good day.
>
> The following:
>
> $ su -c 'abc' -l anotheruser
>
> but it returns
>
> -su: abc: command not found
>
> The abc is in the anotheruser's path, but it seems option '-l' does not
> work here.
>
> How I can accomplish the goal (without manually specifying complete
> path)?
>
>
> Thank You for Your time.

The above command line worked for me. What system are you using, which
shell?

Is this other user's path really getting set? Is 'abc' executable and
is the content runable (in other words, if it's a script and it begins
with '#!/bin/bash', is bash really in /bin, or if it's binary, is the
binary runable for the system you're on)?

You might want to try using the 'echo' or 'env' commands to validate the
environment variables PATH and HOME. You may also want to try running a
normal system command such as 'date', to see if that works.

Good luck.

--
Bob McGowan


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4C366356.6080708(a)symantec.com
From: Bob Proulx on
Sthu Deus wrote:
> $ su -c 'abc' -l anotheruser
> -su: abc: command not found
>
> The abc is in the anotheruser's path, but it seems option '-l' does not
> work here.

A very confusing topic and one often discussed is the process bash
uses to start up and what environment files are processed and at what
times. PATH is usually set in a user's .profile (or .bash_profile).
The .bashrc is not loaded at login time and is usually sourced from
the .profile.

If a user has added PATH to .bashrc and hasn't sourced the .bashrc in
the .profile then something like the above can occur. But that isn't
a "correct" configuration IMNHO.

Try this to print the PATH:

su -l anotheruser -c 'printenv PATH'

> How I can accomplish the goal (without manually specifying complete
> path)?

Put PATH setup in the .profile (or .bash_profile) and source the
.bashrc from the .profile.

If modifying the other user environment is not possible then you would
need to source the files expliclitly.

su anotheruser -c '. ~/.bashrc ; printenv PATH'

Bob
From: Sthu Deus on
Thank You for Your time and answer, Bob:

> > $ su -c 'abc' -l anotheruser
> >
> > but it returns
> >
> > -su: abc: command not found
> >
> > The abc is in the anotheruser's path, but it seems option '-l' does
> > not work here.
> >
> > How I can accomplish the goal (without manually specifying complete
> > path)?
> >
> The above command line worked for me. What system are you using,
> which shell?

I do believe You - recently I had another strange experience and again
w/ bash's 'if' construction like this:

if [ "$a" == --help ]

- in one Debian 5 it worked, another - not!

I use Debian 5 mixture of stable and testing - all updated up-to-day.

Both users use

/bin/bash

version 3.2-4.

> Is this other user's path really getting set? Is 'abc' executable and

No. And here the question arises, Why? As I do understand the su
manual. it says that option '-l' helps to load his (another_user's ENV).

> is the content runable (in other words, if it's a script and it begins
> with '#!/bin/bash', is bash really in /bin, or if it's binary, is the
> binary runable for the system you're on)?

Yes, it is executable - it runs just fine if I do:

su - another_user

and then in its shell run the

abc

w/o specifying the path and the abc is not in CWD.


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4c382a9b.ce7c0e0a.180f.4934(a)mx.google.com