I use python on windows to generate .sh file, simply using file.open(),file.write()
. But when I run this .sh on linux, it reports the following error.
/bin/bash^M: bad interpreter: No such file or directory
The content of my generated .sh file:
#!/bin/bash
export ICS_START=/rdrive/ics/itools/unx/bin/
source $ICS_START/icssetup.sh
......
I found vim recognized it as dos file. I guess if there is something wrong with the newline symbol.
In my python code, I use file.write('xxxx\n')
. To my knowledge, '\n'
is the newline on linux/unix and '\r\n'
is on windows. I don't why there is still ^M
when recognized by linux since I only write '\n'
.
Any help would be appreciated.