I need to generate a file with Unix line endings (\n) in my Windows environment. The following script still generates the default Windows line endings, despite the fconfigure
command. How can I fix this?
set fid [open "myfile.txt" "WRONLY CREAT TRUNC"]
fconfigure $fid -eofchar \n
puts $fid "hello"
close $fid
CodePudding user response:
You need to configure -translation lf
on that channel. (binary
would also work, but that shorthand also changes other features of the channel, such as the encoding and EOF marker.)
fconfigure $fid -translation lf
Don't set -eofchar
to newline; that's very unlikely to be what you want! (It's also not nearly so important on output; we don't automatically write the EOF marker when you close the file.)
CodePudding user response:
Maybe a clarification: -eofchar
is for end-of-file, verus OPs need to set end-of-line character.