0

i have a simple shell script that echoes variable in a file but i have issues getting it work the same way between the different distributions.

The script

#!/bin/sh
res="=1B,\=AB=D2=DB=B5=A6e=FCj=10=0C=EE=91@y\e=082  ="
echo $res

The the result in Ubuntu 20.04.3

=1B,\=AB=D2=DB=B5=A6e=FCj=10=0C=EE=91@y082 =

And result in CentOS 6.0

=1B,\=AB=D2=DB=B5=A6e=FCj=10=0C=EE=91@y\e=082 =

Why Ubuntu is not printing the "\e" and how to make it print it?

Kusalananda
  • 333,661
  • 1
    See Why is printf better than echo?, in particular the discussion around the -e flag – steeldriver Jan 14 '22 at 12:43
  • Already tested printf but it brings other issues that i was unable to solve so i prefer echo. This script is used by Amavis to add disclaimer to email file before sending it out. If i use printf "%s" "$res" > /path/to/file then the DKIM signature added by Amavis is invalid. If using echo the DKIM signature is fine. – Miro Igov Jan 14 '22 at 12:48
  • 2
    Perhaps the signature needs to end in a newline? printf "%s\n" "$res" > /path/to/file – steeldriver Jan 14 '22 at 12:52
  • Yes, newline fixed it. Thank you very much! – Miro Igov Jan 14 '22 at 13:06
  • 1
    /bin/sh in Ubuntu is Dash by default, CentOS probably has Bash. And their implementations of echo differ in how they treat backslash escapes. Bash only processes them with -e, and Dash doesn't seem to have a way to disable it. – ilkkachu Jan 14 '22 at 13:52

0 Answers0