0

To be more specific, what I mean is:

Suppose I have a python script called test.py with a proper shebang on the first line, say

#!/usr/bin/env python

print 'this works'

In the shell, when I type:

$ test.py

Nothing happens, but when I type:

$ ./test.py

The command is invoked and prints "this works".

Why is that? I thought "." just meant the current directory. Why would having a ./ suddenly mean we want to execute whatever comes next? Thanks.

Lucas Ou-Yang
  • 5,505
  • 13
  • 43
  • 62

2 Answers2

4

The shell only looks for executables in the path (try echo $PATH in the shell to see its value). If . is not in the path, you'll have to give the explicit path to the executable. Not having . in the path is a good idea: imagine somebody managed to put an executable named ls in your home directory!

Ulrich Schwarz
  • 7,598
  • 1
  • 36
  • 48
1

Because the current directory (where you had saved test.py) is not in your $PATH environment variable.

$PATH is searched for executables when you try to run one.

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110