Hashbang error

P

pradeepbpin

I use gVim as an editor to create python scripts on a windows machine.
To run the same script on my ubuntu machine, I added a hashbang line
to the script. Now when I run this script from command line of ubuntu,
I get a bad interpreter error, like below

/usr/bin/python^M: bad interpreter: No such file or directory

This, I understand, is due to the interpretation of newline character
at the end of the hashbang.

I have checked and found out that this does not happen if I create the
script in Ubuntu with gVim.

Now, how can I avoid this error when I create the script on a windows
machine?
 
C

Cameron Simpson

| I use gVim as an editor to create python scripts on a windows machine.
| To run the same script on my ubuntu machine, I added a hashbang line
| to the script. Now when I run this script from command line of ubuntu,
| I get a bad interpreter error, like below
|
| /usr/bin/python^M: bad interpreter: No such file or directory
|
| This, I understand, is due to the interpretation of newline character
| at the end of the hashbang.
|
| I have checked and found out that this does not happen if I create the
| script in Ubuntu with gVim.
|
| Now, how can I avoid this error when I create the script on a windows
| machine?

The standard approach is to copy the file to the unix machine and use
the dos2unix command.
 
R

Rebelo

I use gVim as an editor to create python scripts on a windows machine.
To run the same script on my ubuntu machine, I added a hashbang line
to the script. Now when I run this script from command line of ubuntu,
I get a bad interpreter error, like below

/usr/bin/python^M: bad interpreter: No such file or directory

This, I understand, is due to the interpretation of newline character
at the end of the hashbang.

I have checked and found out that this does not happen if I create the
script in Ubuntu with gVim.

Now, how can I avoid this error when I create the script on a windows
machine?


check if there is an option like in Geany to select encoding and line
endings
 
C

Chris Gonnerman

pradeepbpin said:
I use gVim as an editor to create python scripts on a windows machine.
To run the same script on my ubuntu machine, I added a hashbang line
to the script. Now when I run this script from command line of ubuntu,
I get a bad interpreter error, like below

/usr/bin/python^M: bad interpreter: No such file or directory

This, I understand, is due to the interpretation of newline character
at the end of the hashbang.

I have checked and found out that this does not happen if I create the
script in Ubuntu with gVim.

Now, how can I avoid this error when I create the script on a windows
machine?
In gvim, type:

:se ff=unix

then resave the file. Once it's in unix format, gvim won't change it
back to dos unless you tell it to.

-- Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top