Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

Platform: Ubuntu 10.04 VM running out of VirtualBox

File details:

-rwxr-x---  1 myuser myuser  123 2013-10-31 16:10 myscript.sh

The executable is visible in the directory:

>type myscript.sh
myscript.sh is ./myscript.sh

I do have . in the path:

>echo $PATH
.:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Running it without sudo works fine:

>myscript.sh

but not with sudo:

>sudo myscript.sh
sudo: myscript.sh: command not found

Why?

share|improve this question

marked as duplicate by slm, jasonwryan, warl0ck, Anthon, manatwork Nov 1 '13 at 7:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
PATH is not inherited in sudo. Doing so would be a security flaw since someone might stick something unsafe in PATH such as .. –  jordanm Oct 31 '13 at 20:32

1 Answer 1

http://serverfault.com/questions/11899/how-to-override-a-path-environment-variable-in-sudo

"Sudo resets PATH, along with many other environment variables, for security reasons. It doesn't matter what is set in /etc/profile, unless you run sudo -i.

The sudo manual page, under SECURITY NOTES, gives an insight about the security implications, along with the options you have to fiddle in your /etc/sudoers file to modify these restrictions, after you understand the implications of doing so."

share|improve this answer

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