3 ms·
Yes, you probably want su rather than su -. He uses sh only to run some command but that's obviously superflous, he should just use su -c. The fact that he sour
by 4ad 14y ago
Yes, you probably want su rather than su -. He uses sh only to run some command but that's obviously superflous, he should just use su -c. The fact that he sources the user's profile is hilarious. The fact that this remarkably poor and trivial article made it to the HN front page is sad.
- StavrosK 14y ago> The fact that he sources the user's profile is hilarious. Why is that? Also, if all he wants is to run a command, why not use sudo? Isn't that what sudo is supposed to do (i.e. pretty much what su -c does)?
- 4ad 14y ago> Why is that? Because he just did a login: silver:aram$ sudo su aram -c 'echo $PATH' /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games silver:aram$ sudo su - aram -c 'echo $PATH' .:/home/aram/bin:/home/aram/bin/linux:/home/aram/bin/linux/amd64:/home/aram/bin/linux/386:/home/aram/go/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/games:/usr/local/bin:/usr/local/sbin:/home/aram/plan9/bin silver:aram$ sudo su - aram -c '. ~/.profile; echo $PATH' .:/home/aram/bin:/home/aram/bin/linux:/home/aram/bin/linux/amd64:/home/aram/bin/linux/386:/home/aram/go/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/games:/usr/local/bin:/usr/local/sbin:/home/aram/plan9/bin > why not use sudo? Isn't that what sudo is supposed to do (i.e. pretty much what su -c does)? Sure, he could have used sudo.
- runlevel1 14y agoCareful adding '.' to your $PATH, particularly as the first item. It makes it awful easy to execute something you forgot/didn't know was in the current working directory. UPenn gives a pretty good explanation here: http://www.seas.upenn.edu/cets/answers/dot-path.html http://www.seas.upenn.edu/cets/answers/dot-path.html The security issue is most relevant on multi-user systems, including hosted services (e.g. a web server with an upload feature and misconfigured umask). I don't do it on my personal system either because I am my own worst enemy and am frequently saved by the Unix "rule of least surprise." It's the usual convenience/risk balance. To each his own.