running a python program in the command line without "./"

Viewed 20

Let's say I have a program called "hello". It is a python script and I want to run it at the linux command line.

I've been able to remove the .py extension as well as the interpreter.

Now when I run it it is [user..path] $ ./hello

it works, but how do I remove the "./". I've already applied the chmod a+x argument to the file and a shebang line at the front of my script.

Basically, I am asking how to run the script as $ hello

1 Answers

Add . to the end of your $PATH variable.

PATH=$PATH:.

Then it will search the current directory when looking for programs to run.

Note that you should not generally put . at the beginning of $PATH. If you cd into someone else's directory, and they have a program that's the same name as a system program (e.g. ls), you'll execute their version instead of the real one.

You could also create your own directory where you install programs, and put that directory in $PATH.

PATH=~/bin:$PATH

Now you copy hello to your ~/bin directory and run hello.

Related