Tag Archives: syntax error: invalid arithmetic operator (error token is “

[Solved] Shell Error: syntax error: invalid arithmetic operator (error token is “

When processing windows format text, use \r\n as the newline character, if the data involved in the operation is at the end of the line

syntax error: invalid arithmetic operator (error token is “

https://stackoverflow.com/questions/43309793/remove-rn-in-awk

awk -v RS= ' \r\n ' ...

 

awk  ' { sub("\r$", ""); ...}
awk  ' {sub(/\r/,"",$NF); ...} '
awk  ' BEGIN { RS=ORS="\r\n"; ...

 

foo=$ ' 5\r ' ; echo $(( 5 + foo))

" )syntax error: invalid arithmetic operator (error token is "

 

foo=$ ' 5\r ' ; echo $(( 5 +${foo // $'\r'}))

 

foo=$ ' 5\r ' ; echo $(( 5 +$( tr -d ' \r ' <<< " $foo " )))

 

or remove \r

foo=$ ' 5\r ' ; foo=${foo // $'\r'}