[Novalug] shell tidbit (accidental embedded return newline)

Doug Toppin dougtoppin@gmail.com
Tue Jul 8 17:52:50 EDT 2008


here's a little tidbit on something that causes me to waste 10 or 15
minutes every now and then when i'm messing with shell scripts.
occasionally when i copy using the mouse into a vim session where i'm
editing a shell script i'll end up with a script that won't run (or do
anything actually).  every single time this happens i'll think that
the problem is somewhere else when it is actually that a carriage
return newline ( backslash r backslash n) has gotten put into the
script.  the result of this is that the shell can't read the line
correctly and interprets the command(s) wrong (it thinks the carriage
return is part of the command and can't find it in the file system)
with a potentially confusing error message (like '  :command not
found') when you try to run it.  a clue that this is happening (with
vim anyway) is that vim will include something like ...[dos format]...
in the output as you're saving the file.  you can see the result if
you do a 'od -c filename'.  if this has happened you should see a
backslash r  backslash n here and there in the file contents.
there are a variety of ways to fix the file (tounix and some others)
but the easiest way that i've found is to just do a ':set
fileformat=unix' while in vim and then save the file back (and the
[dos format] should not appear).  i'm passing this along because it
just happened to me again (for about the hundreth time in my life).
note that you can also do a :set fileformat=dos to do the converse.

doug



More information about the Novalug mailing list