Help! My script won't execute.
It's obviously there.
Permissions are correct too.
Looks fine.
I also have cshell or tcshell installed and the path is correct on my shebang line.
So what could it be? Let's look at the actual contents.
I didn't put those funny ^M thingies in there. I'll just remove them.
On Linux you say to yourself, "Self, where's the flaming editor at? Oh doh! I'm not on Windows anymore. I know. I'll just ftp the file down to my Windows machine, edit it and upload it. Yeah, that's what I'll do.". Or Cygwin you are in the flaming notepad editor and can't see any ^M thingies. Well the ^M thingies are called Carriage returns. The EOL or end of line sequence on DOS/Windows?/OS2 is CRLF or carriage return followed by linefeed, or in C parlance, "\r\n", or in ASCII (015)(012). The EOL used by Unix-based systems is LF, "\n" or (012). Luckily most well written Unix tools recognize ANSI X34 standards for EOL and handle the \r\n EOL sequence (i.e. gcc, make, etc.). Some don't. In particular, bash, cshell, and tcshell do not, well especially when found on the shebang line; #!/bin/csh^M causes the shell to search for the program named "csh\r". Rule Number OneDon't use notepad. Don't even use it on Window's files. It will even mess up application configuration files for Windows apps that happen to look like text, but contain special characters (i.e. tabs).''' You can get away with using wordpad (write) as long as you remember to save the file as text and not rtf format, and don't do tab to space conversions. Use either a unix editor or use textpad, ultraedit or another windows editor that recognizes and preserves EOL sequences, and other control characters. Okay so how do I convert them back... If you have perl do this:
Note do not try redirecting input and output to the same file. It'll magically disappear. There's a way of getting around this but I forget it. Darklord says here's the way..
Perl will make a backup of each file processed ending in ~. If you don't have perl, use sed.
Careful with that one above as it assumes all lines end in CRLF and strips off the last character. If you use vim or vi you can edit a DOS/Windows? format file and force a change to the save format with the command ":se ff=unix" If you have cygutils installed on cygwin, and I do recommend it, you've got dos2unix, unix2dos, d2u, u2d.
Conversion in place. Quite handy. I believe some Linux distros now ship dos2unix or conv
Finally FTP supports automatic CRLF to LF and LF to CRLF conversion by using the 'ascii' command to set the transfer mode before uploading or downloading a file. One uses 'binary' to get back to binary mode transfer. One warning though, don't forget switch back to 'binary' mode before ftp-ing binaries like zips, exes, tars and gzipped files around, as they will be mercilessly destroyed in transfer. |
Help! My script won't execute.
It's obviously there.
Permissions are correct too.
Looks fine.
I also have cshell or tcshell installed and the path is correct on my shebang line.
So what could it be? Let's look at the actual contents.
I didn't put those funny ^M thingies in there. I'll just remove them.
On Linux you say to yourself, "Self, where's the flaming editor at? Oh doh! I'm not on Windows anymore. I know. I'll just ftp the file down to my Windows machine, edit it and upload it. Yeah, that's what I'll do.". Or Cygwin you are in the flaming notepad editor and can't see any ^M thingies. Well the ^M thingies are called Carriage returns. The EOL or end of line sequence on DOS/Windows?/OS2 is CRLF or carriage return followed by linefeed, or in C parlance, "\r\n", or in ASCII (015)(012). The EOL used by Unix-based systems is LF, "\n" or (012). Luckily most well written Unix tools recognize ANSI X34 standards for EOL and handle the \r\n EOL sequence (i.e. gcc, make, etc.). Some don't. In particular, bash, cshell, and tcshell do not, well especially when found on the shebang line; #!/bin/csh^M causes the shell to search for the program named "csh\r". Rule Number OneDon't use notepad. Don't even use it on Window's files. It will even mess up application configuration files for Windows apps that happen to look like text, but contain special characters (i.e. tabs).''' You can get away with using wordpad (write) as long as you remember to save the file as text and not rtf format, and don't do tab to space conversions. Use either a unix editor or use textpad, ultraedit or another windows editor that recognizes and preserves EOL sequences, and other control characters. Okay so how do I convert them back... If you have perl do this:
Note do not try redirecting input and output to the same file. It'll magically disappear. There's a way of getting around this but I forget it. Darklord says here's the way..
Perl will make a backup of each file processed ending in ~. If you don't have perl, use sed.
Careful with that one above as it assumes all lines end in CRLF and strips off the last character. If you use vim or vi you can edit a DOS/Windows? format file and force a change to the save format with the command ":se ff=unix" If you have cygutils installed on cygwin, and I do recommend it, you've got dos2unix, unix2dos, d2u, u2d.
Conversion in place. Quite handy. I believe some Linux distros now ship dos2unix or conv
Finally FTP supports automatic CRLF to LF and LF to CRLF conversion by using the 'ascii' command to set the transfer mode before uploading or downloading a file. One uses 'binary' to get back to binary mode transfer. One warning though, don't forget switch back to 'binary' mode before ftp-ing binaries like zips, exes, tars and gzipped files around, as they will be mercilessly destroyed in transfer. More ways... If you have ruby installed you can do the following one liners:
|