I made a bin directory in my home folder where I place all my scripts. Then in my .bashrc I added the following:
export PATH=$PATH:/home/myusername/bin
So I could access files I placed in there from anywhere. But some of the scripts need to be executed as root. So I thought, I could symlink my .bashrc as root, (as in /root/.bashrc points to /home/myusername/.bashrc, don't know if this is smart) so when I need to run a script as root I can just do:
sudo program_that_requires_root
But then I get a:
sudo: program_that_requires_root: command not found
If I login as root and execute the program, it works fine though. So what is the correct way to accomplish what I want?

sudoprobably is usingsecure_pathinstead of your$PATH. Runsudo -Vas root (e.g.sudo sudo -V) and look for lines that containPATH. – jw013 Oct 18 '12 at 17:14/etc/sudoersand find this line:Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin(paths may vary) - if you add your userbinpath, it'll work. (Perhaps that solution is not recommended for other reasons; I don't know.) Oh, in the file mentioned, it says you shouldn't change it, but I did, and it works great, at least in terms of what I tried to achieve (having the same problem as you). – Emanuel Berg Oct 18 '12 at 19:27