0

I got a line of code in bash that is supposed to output this:

identity="A273927A49D0" (The content of identity is stored in $usercaps)

My line of code is: echo "identity=\"$usercaps\"" >> ttls.conf

However if I do that, the output becomes: identity="A273927A49D0^M"

I can get around it by adding this: echo "identity=\"$usercaps\"" | sed 's/\r//' >> ttls.conf

Why is this happening and is this the only way to deal with it?

Simon
  • 11
  • What o/s are you running on? – rghome Jan 15 '19 at 10:07
  • 2
    Then `usercaps` contains `^M` -- how are you obtaining this value? – tripleee Jan 15 '19 at 10:10
  • `$usercaps` contains the string A273927A49D0. `echo "$usercaps"` gives me `A273927A49D0` The problem arises when I `echo` my string that contains the variable `$usercaps` and the string must also contain quotes. – Simon Jan 15 '19 at 11:21
  • When you `echo $usercaps >> ttls.conf` and `less ttls.conf` do you get the ^M after the variable? How are you setting `$usercaps`? – itChi Jan 15 '19 at 12:39
  • take a look at this: https://stackoverflow.com/questions/37854454/is-there-a-way-to-prevent-sed-from-adding-carriage-return-m – itChi Jan 15 '19 at 12:41

0 Answers0