1

OK, I'm having a bit of an issue with PATH and running a process as another user under Ubuntu.

First, we check where the bin is:

root@host:~# whereis start-stop-daemon
start-stop-daemon: /sbin/start-stop-daemon /usr/share/man/man8/start-stop-daemon.8.gz

ok, /sbin/start-stop-daemon so ti's in /sbin. then we check path as a user we want to run the app:

root@host:~# su wojtek -c "echo $PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

root@host:~# su -l wojtek -c "echo $PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

in both cases the PATH is exactly the same (ie. in normal su and with full login) yet there is a distinction when we actually want to run the command:

root@host:~# su wojtek -c "start-stop-daemon"
bash: start-stop-daemon: command not found

root@host:~# su -l wojtek -c "start-stop-daemon"
start-stop-daemon: need one of --start or --stop or --status
Try 'start-stop-daemon --help' for more information.

Can somebody try to explain where the difference comes from? Because for me there shouldn't be any error as there is no difference in PATH thus $start-stop-daemon for a given user should work either way...

also - if I switch to different user ($su user and $su - user) then $start-stop-daemon in both cases...

what am I missing?

1
  • 1
    Why are you logged in as root?
    – Alvar
    Jun 19, 2013 at 12:21

1 Answer 1

2

The path appears to be the same in your two statements because $PATH has been expanded within the double quotes before being passed to the su command.

Try it with single quotes and I think you'll be pleasantly surprised:

su wojtek -c 'echo $PATH'

vs

su -l wojtek -c 'echo $PATH'
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .