Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If I try "shutdown" as a normal user on Debian it give the "command not found" error. OK it's not in my PATH. But if I "sudo shutdown" it works. Somehow sudo seems to change my PATH.
Do the same in Slackware however and sudo makes no difference, I get "command not found" each time.
The sudo command lets a user run a command as another user. It probably does this by launching another shell process as that user, and then runs the command. I emphasize "probably" because I haven't looked at the code to know for sure.
Assuming that is the case, then the PATH when the command is executed will be created/modified by shell startup files (e.g. for bash: /etc/profile, ${HOME}/.bash_profile, etc. -- see man bash for a list of the files bash reads).
So, it's likely that any PATH problems you encounter are a result of the shell startup files for the user you're trying to act as.
@alar - I think you misunderstand, I have sudo installed and configured in slackware, as I do in debian. My point being that it (apparently) behaves differently in the two different distros despite being the same package.
@Dark_Helmet - that sounds like it makes sense, as the profile, bash_profile bashrc etc settings are almost certainly different in the two distros. I'll look into it, thanks.
First make sure there is not any aliases for sudo.
Secondly, check each users PATH. shutdown is usually in /sbin and not all users have /sbin in their default path, Slackware seems to have this for regular users by default.
Thirdly, it's not sudo but rather the default path of the user.
Remember, when you run sudo, it retains your current users default path. When you use sudo to su as another user (example root), you are still basically carrying over your environment settings, which includes path, etc. To take on the full path of another user, that's when you do something like sudo su - <user>
First make sure there is not any aliases for sudo.
Secondly, check each users PATH. shutdown is usually in /sbin and not all users have /sbin in their default path, Slackware seems to have this for regular users by default.
Thirdly, it's not sudo but rather the default path of the user.
Remember, when you run sudo, it retains your current users default path. When you use sudo to su as another user (example root), you are still basically carrying over your environment settings, which includes path, etc. To take on the full path of another user, that's when you do something like sudo su - <user>
Thanks for the reply trickykid but I don't think you read the question properly. I already said in the opening post that neither user has /sbin in their PATH. I also said that it is only the preface sudo command that allows me to run shutdown, but that this behaviour is inconsistant between the two users/distros.
So why can I run sudo shutdown from my normal debian user account but not my normal slackware user account, when both accounts have the same PATH?
If Dark_Helmet were correct then the new shell process would gain root bash profile settings (and therefore PATH) as well as root authority, in both cases.
So why can I run sudo shutdown from my normal debian user account but not my normal slackware user account, when both accounts have the same PATH?
So did you also verify if there's not a link or another shutdown command in the given path that the other distro doesn't have?
Honestly, why does it matter? Different distro's are just that, they're slightly different from one another. If you want your distro's to behave the same, run the same distro on both machines.
You can setup sudo to change the environment (and with this the PATH). This configuration is done in the sudoers-file. Compare the sudoers-file on both systems and check
Honestly, why does it matter? Different distro's are just that, they're slightly different from one another. If you want your distro's to behave the same, run the same distro on both machines.
Why does it matter? Why are you even posting that stupid question? Because i'm curious about linux; that's why i'm posting on a forum called 'linuxquestions' dummy.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.