I have a problem with a character. I think this is a conversion problem between dos and unix.
I have a variable that is a float value. When I print it using the echo command, I get:
0.495959
But when I try to perform an operation on this value using the bc command (I'm 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 in my .sh file. I think because my variable has the ^ M character (not printed with echo command)
How can I fix this error?
Cygwin, Bash tr -d , $'...' ( , , C/Java/Perl/ ..). , :
tr -d
$'...'
echo "$mean" * 1000 | tr -d $'\r' | bc
echo bc.
echo
bc
, :
mean=$(echo "$mean" | tr -d $'\r')
$mean, , , .
$mean
( , $mean . $mean , ? , .)
:
${mean/^M/}
^ M, Ctrl-V, Ctrl-M. , :
${mean/$(printf "\r")/}
@ruakh , bash . , .
"unixize" $mean:
mean="${mean/^M/}"
: :
${mean/$'\r'/}
, script UNIX DOS.
Windows- cygwin , - Windows cygwin bash CR .
d2u - ,
runtime="`mediainfo --Inform='Video;%Duration%' ${movie} | d2u`"
( d2u, ${runtime} CR, , , , "bc", .)
echo `echo $mean` *1000 |bc
, .
^M , Windows (\n) . , , UNIX, bash , . , , . dos2unix , .
^M
\n
bash
dos2unix
, Windows. , , .
WINDOWS, Cygwin. CRLF . , , , .
Windows, Winpad.
. . VI, VIM, Windows Cygwin ( Unix). VIM , Notepad ++. Unix Windows Windows Cygwin.
VIM, , :
:set ff?
:set ff=unix
:set ff=dos
Notepad ++
Mac
Unix