Mailing List Archive

Python and Red Hat Linux 6.0
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?
Python and Red Hat Linux 6.0 [ In reply to ]
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?
Python and Red Hat Linux 6.0 [ In reply to ]
On Mon, 26 Jul 1999 13:53:20 -0700, Rob <vaton@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@es.co.nz>
Python and Red Hat Linux 6.0 [ In reply to ]
Rob 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?


I also recently had a similar problem, I had created the
files using Wordpad and saved them to the Linux server. I
thought I was using a UNIX-safe text format, but I later
discovered it was in DOS text format. Just another idea.
Python and Red Hat Linux 6.0 [ In reply to ]
Rob <vaton@postoffice.pacbell.net> writes:

> 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?

Did you do `chmod +x' on the file?
Did you start it with `./script', or did you start it with `script'?

On RH, the current directory `.' is not in your path by default
for security reasons, so you have to mention the path explicitely.

BTW, it's not the shell that interprets the `#!...' line.
It's the kernel. (If it was just the shell, it would be just as
useless as those braindead Windows "shortcuts", sorry for the rant.)

Greetings,

Stephan