John Stolz <china_rider.RemoveThis@wanadoo.fr> wrote:
> How do I save a file with textedit so I can use it in terminal.
Easiest option in this situation is not to use TextEdit. Use the free
TextWrangler (from Bare Bones) instead, or BBEdit, its commercial big
brother.
If you need to use TextEdit, then read on...
The Unix command line tools in Terminal mostly deal with ASCII text
files. You should use TextEdit's "Make Plain Text" command, choose to
save the file in an encoding format which is as close to ASCII as
possible, and avoid the use of non-English characters.
The best encoding format to pick is probably of the normally hidden
ones, such as "Western (ASCII)", which can be enabled if you use the
"Customize Encodings List" item in the encoding popup menu.
The default "Unicode (UTF-

" encoding should also work as long as you
avoid accents and symbols which require the use of the Option key with a
US keyboard.
Terminal can display non-ASCII characters (it defaults to UTF-

but
most of the command line tools won't handle UTF-8 sequences which
represent characters outside the basic character set.
> I've tried various plain text encoding options, but the files end up
> being either binary or, when I do 'cat' on them, the line breaks are
> replaced by '^M' and the file appears to be one line.
Binary might appear if you start to dabble with non-Western-European
languages, or pick "Unicode (UTF-16)".
I don't know how you got '^M'. That is the representation of a
Control-M, or Carriage Return (CR for short), which is the traditional
Macintosh line break character in text files, used by Mac OS 9 and
earlier. Was this an old file you were modifying in TextEdit?
For newly created text files, TextEdit uses ^J (Line Feed, LF for short)
as the line break character. This matches what the Unix tools in
Terminal expect, and is the standard for Mac OS X.
To confuse things further, there is a third standard: MS-DOS and Windows
use both CR and LF as a pair.
This typically means a conversion is required when copying text files
between systems, unless you are displaying the file in an application
which can automatically convert the line endings if it finds the wrong
type.
Some editors (notably BBEdit and its free sibling TextWrangler) have a
setting which lets you set the type of line break to use (Mac, Unix or
MS-DOS). I can't see any way to do that in TextEdit.
TextEdit can open files with varying line endings, and displays a line
break for any of CR, LF, or CR followed immediately by LF. Any editing
changes are done using the Unix/Mac OS X standard, with just a LF for
the line break when the document is saved. This can be confusing, as you
end up with a file with mixed line break standards, which most software
won't handle correctly.
Unix tools in Terminal will display CR as "go back to the start of the
current line", so a Mac OS 9 text file will be displayed with every line
overwritten by the next one. An MS-DOS/Windows file (CR and LF) will
look right, as the CR and LF as a pair have the same effect as LF by
itself.
--
David Empson
dempson.RemoveThis@actrix.gen.nz