bash CRLF problems (I have read the recent announcement)
Mark Fisher
mark.j.fisher@gmail.com
Tue Dec 5 12:30:00 GMT 2006
On 12/5/06, Kevin Layer <layer at franz.com> wrote:
> Larry Hall (Cygwin) <reply-to-list-only-lh at cygwin.com> wrote:
>> >> > version=`cat foo1.out`
> >> > ...
> >> Time to adjust your expectations. ;-) Text mounts write CRNL as EOLs
> >> for all files that are not explicitly opened as binary (or text for
> >> that matter). Text mounts remove the CR from EOLs read from files that
> >> are not explicitly opened as binary (or text). 'cat' explicitly opens
> >> the file as binary.
>> What is the portable way to get the contents of foo1.out into a
> variable, getting proper translation of the end of lines? (If the
> answer is use `d2u' that is not portable.) I thought I was safe by
> using text mounts--I spent quite a while looking at the archives
> before posting and thought I had covered all bases.
>> Kevin
>
if you change the echo's to "echo -n" you don't get the ^M chars, as
it surpresses the CR in the output.
is this possible on the "real" scripts you talk about, or is the
version generating script/app not changeable?
$ cat foo1.sh
echo -n 8010 > foo1.out
$ cat foo2.sh
sh foo1.sh
version=`cat foo1.out`
echo -n ${version}.bar > foo2.out
cat -v foo2.out
$ sh foo2.sh
8010.bar
alternate solutions to using cat (which allow the \r\n in foo1.out) :
version=`cut -f1 foo1.out`
version=`awk '{print 1ドル}' foo1.out`
version=`sed -n '1p' foo1.out`
cat is doing what it's supposed to, putting the whole file in the variable.
don't use it. if you can't change the \r\n from your version file, use one
of the alternatives.
mark
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list