public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Illegal character ^M
@ 2011-11-29 20:16 frenco
  2011-11-29 21:41 ` Tim McDaniel
  2011-12-03  7:32 ` Erwin Waterlander
  0 siblings, 2 replies; 3+ messages in thread
From: frenco @ 2011-11-29 20:16 UTC (permalink / raw)
  To: cygwin


I have a problem with a character. I think it's a conversion problem between
dos and unix.

I have a variable that is a float value.
When I print it with the echo command i get:
0.495959
But when I try to make an operation on that value with the bc command (I am
not sure how to write the bc command).
echo $mean *1000 |bc

 I get:
(standard_in) 1 : illegal character: ^M

I already use the dos2unix command on my .sh file.
I think it's because my variable have the ^M character (not printed with the
echo command)

How can i eliminate this error?

I already try a lot of things but I am really lost.

Any thought?
-- 
View this message in context: http://old.nabble.com/Illegal-character-%5EM-tp32881791p32881791.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Illegal character ^M
  2011-11-29 20:16 Illegal character ^M frenco
@ 2011-11-29 21:41 ` Tim McDaniel
  2011-12-03  7:32 ` Erwin Waterlander
  1 sibling, 0 replies; 3+ messages in thread
From: Tim McDaniel @ 2011-11-29 21:41 UTC (permalink / raw)
  Cc: cygwin

On Tue, 29 Nov 2011, frenco wrote:
> I have a variable that is a float value.
> When I print it with the echo command i get:
> 0.495959
...
> I think it's because my variable have the ^M character (not printed
> with the echo command)

You might try
     echo "[$the_variable_name]"
The quoting is significant.  If it does have a carriage return like
you think, then it will probably display like
     ].495959
That is, the ^M will probably make it go back to the start of the
line, and characters after it (here, ]) will overwrite what it output
before.

> But when I try to make an operation on that value with the bc
> command (I am not sure how to write the bc command).
> echo $mean *1000 |bc
...
> How can i eliminate this error?

     echo $mean *1000 | tr -d '\r' | bc
seems to work.  "tr" translates characters, "-d" says that instead of
translating it should just delete the name characters, and '\r' (note:
single quote ', not double quote ") is the ^M character.

-- 
Tim McDaniel

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Illegal character ^M
  2011-11-29 20:16 Illegal character ^M frenco
  2011-11-29 21:41 ` Tim McDaniel
@ 2011-12-03  7:32 ` Erwin Waterlander
  1 sibling, 0 replies; 3+ messages in thread
From: Erwin Waterlander @ 2011-12-03  7:32 UTC (permalink / raw)
  To: cygwin, frencoo

frenco schreef, Op 29-11-2011 19:57:
> I have a problem with a character. I think it's a conversion problem between
> dos and unix.
>
> I have a variable that is a float value.
> When I print it with the echo command i get:
> 0.495959
> But when I try to make an operation on that value with the bc command (I am
> not sure how to write the bc command).
> echo $mean *1000 |bc
>
>   I get:
> (standard_in) 1 : illegal character: ^M
>
> I already use the dos2unix command on my .sh file.
> I think it's because my variable have the ^M character (not printed with the
> echo command)
>
> How can i eliminate this error?

Hi,

Dos2unix will convert only DOS line breaks to Unix line breaks. Meaning 
\r\n to \n.
When you see a single \r (^M), without a following \n, this is a Mac 
line break.
Dos2unix will leave Mac line breaks alone.
So you need to run mac2unix instead of dos2unix on the file.

regards,

-- 
Erwin Waterlander
http://waterlan.home.xs4all.nl/


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-12-03  7:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-29 20:16 Illegal character ^M frenco
2011-11-29 21:41 ` Tim McDaniel
2011-12-03  7:32 ` Erwin Waterlander

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).