Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
1  
Why are you logged in as root? –  Alvar Jun 19 '13 at 12:21
add comment

1 Answer

up vote 1 down vote accepted

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'
share|improve this answer
    
Also read the output of the second command more carefully, start-stop-daemon was found, you need to provide an argument. See also ubuntuforums.org/showpost.php?p=6188826&postcount=4 –  bodhi.zazen Jun 19 '13 at 15:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.