![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| editor mode in cygwin | himvat | Shell Programming and Scripting | 5 | 12-16-2008 04:45 AM |
| cygwin vi editor | mostafamagdy | UNIX for Dummies Questions & Answers | 1 | 11-19-2008 08:07 AM |
| vi editor in cygwin | arparwan | UNIX for Dummies Questions & Answers | 1 | 01-07-2008 04:23 PM |
| E:348 no string under cursor error comes in vi editor in cygwin | mrityunjay22 | Shell Programming and Scripting | 0 | 12-25-2007 09:52 AM |
| A beginner for cygwin simple question | zhshqzyc | UNIX for Dummies Questions & Answers | 1 | 08-06-2007 02:27 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I ran into this issue and thanks to various postings in various forums, was
able to figure out the solution but didn't see one posting that laid the whole issue out cleanly. So thought the following might help others ... ------------------------------------------------------------------------ The Problem You use vim to create a simple shell script in a cygwin directory but the script doesn't run properly. Example: A script called test.sh: #! /bin/sh ls echo "++++++" cat a1.txt produces this when run: $ ./test.sh ./test.sh: line 2: $'ls\r': command not found ++++++ : No such file or directory ------------------------------------------------------------------------ The Solution The problem is that vim has written the file in "DOS mode", which puts an extra (as far as cygwin is concerned) carriage return (aka: control-M, ^M, \r) at the end of each line. You can see that using the "-v" option with cat: $ cat -v test.sh #! /bin/sh^M ls^M echo "++++++"^M cat a1.txt^M The solution is to bring the file back into vi, set vim into binary mode with the ":se binary" command, then save the file. Now, "cat -v" shows that the carriage returns have been removed: $ cat -v test.sh #! /bin/sh ls echo "++++++" cat a1.txt And the program runs just fine: $ ./test.sh 760log2trk.pl a1.txt spot.gpxcon.pl.rc 760log2trk.pl.rc a2.txt spot.gpxcon.tailers.kml ++++++ This is a file with a few lines of text in it. ------------------------------------------------------------------------ Note 1: The first line of the script file is common practice for a Unix script, but isn't really required for the script to work in cygwin. Note 2: Running the script by putting "./" in front of it is required in cygwin as long as you don't have "." (the current directory) in the search path. By default, cygwin doesn't include the current directory when looking for commands. And for security reasons, it's not a good practice to put . in your search path. Note 3: Having saved the file in binary mode, you don't need to worry about that setting for future edits of the file. vim will recognize the nature of the file when it opens it and will keep it in that mode, so lines added to the file will not be written with the carriage return. (vim tells you that the file is in binary mode by putting "[unix]" after the file name at the bottom of the window.) Last edited by otheus; 03-08-2009 at 11:23 AM.. Reason: added lightbulb icon, edited subject |
![]() |
| Bookmarks |
| Tags |
| cool tips, cygwin, script, vim |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|