Python and Red Hat Linux 6.0
Ben Caradoc-Davies
bmcd at es.co.nz
Tue Jul 27 17:53:56 EDT 1999
On Mon, 26 Jul 1999 13:53:20 -0700, Rob <vaton at postoffice.pacbell.net> wrote:
>When programming in Perl or Python, I am using a header like the
>following on an executable file to cause the shell (bash or csh) to run
>the scripts as Perl/Python files:
>#!/usr/bin/perl for Perl and #!/usr/bin/python for Python. I've
>checked and the compilers are located in the appropriate directories. I
>keep getting this when I run scripts:
>bash: <script name>: command not found. Does Linux support the '#!'
>notation in the file header, or do I always have to run the scripts by
>explicitly typing in 'perl' or 'python' before the script name?
Every decent Unix supports #! shell scripts. Linux is one of them. As far as I
understand it, #! is just a different magic number that allows the kernel's
binary format handlers to detect the script in the same way that 0x7f then
"ELF" marks an elf executable.
If you're interested, check out
/usr/src/linux/fs/binfmt_script.c
When an image is exec'ed, the kernel applies all the binary format handlers it
knows in succession, until one works.
As for your problem:
1) Check your PATH. If . is not in your path, you have to run the script
as ./scriptname
This is my best guess as to your problem, given your symptoms.
2) Check your script. It's easy to write !#/usr/bin/python by accident,
with your mind moving faster than your fingers. But for this problem
you get different errors.
3) chmod +x scriptname
However, this will give you "Permission denied." if you forget. This is
a common problem, especially if you use an editor which resets the
permissions whenever you save.
--
Ben Caradoc-Davies <bmcd at es.co.nz>
More information about the Python-list
mailing list