I have a Bash script on my desktop called highest.
If I run:
cd ~/Desktop
highest
I get: Command not found
But if I run:
~/Desktop/highest
It executes just fine. But why do I still need to use the absolute path when my command line is in the correct directory?
I am guessing this has something to do with the $PATH variable. Like I need to add something like ./ to it. If so, how do I add that? I am not used to Linux yet and get very confused when this happens.
I agree with @Dennis’s statement. Don’t add ‘.’ to your PATH. It’s a security risk, because it would make it more possible for a cracker to override your commands. For a good explanation, see http://www.linux.org/docs/ldp/howto/Path-12.html .
For example, pretend I was a cracker and I created a trojaned files like /tmp/ls , like so. Pretend that this was on a shared system at a university or something.
What would happen if you were in the /tmp directory and executed the ‘ls’ command? If
PATHincluded., then you would execute /tmp/ls , when your real intention was to use the default ‘ls’ at /bin/ls.Instead, if you want to execute your own binaries, either call the script explicitly (e.g.
./highest) or create your own bin directory, which is what most users do.Add your own ~/bin directory, and place your own binaries in there.
Then, modify your PATH to use your local binary. Modify the PATH statement in your .bashrc to look like this.
export PATH=$PATH:~/bin
To verify that
highestis your path, do this: