Preserve extented ascii character when run echo comand inside bash script

Hi everyone,

I'm echo some text with extended ascii characters as below:

echo -e "Pr\xE9sentation du spectacle" > output

or

echo -e "Pr�sentation du spectacle" > output

If I open the file created I see this text

Pr�sentation du spectacle

The text is shown correctly in this created file when I run the "echo" script independently, but when I run the same script
inside a large script, the extended ascii characters are not printed. My Script looks like this:

#!/bin/bash

awk '...' input1 > output1
sed '...' input2 > output2

"some bash script" > output3

#My echo script
echo -e "Pr\xE9sentation du spectacle" > output4

When I open output4, the "�" character is not printed.

I'm not sure why only works when I run the echo script alone and fails when is part of another bash script.

How can I fix this?

Thanks in advance

Do a dump of output4 with

od -t x1 output4

Hi binlib, thanks for answer,

But how to save (see as "normal" text) the file with the ascii characters? when I sent that command the output is hexa a below:

$ od -t x1 output4
0000000 50 72 e9 73 65 6e 74 61 74 69 6f 6e 20 64 75 20
0000020 73 70 65 63 74 61 63 6c 65 0a
0000032

Thanks for the help

Regards

The file has the right content. Here you see the third byte has the value "e9" which came from "\xE9" from your echo command. It must be that your terminal (or the application that you used to open the file) settings are different between the one that you can see it and the one you can't.

You need to change your locale to a french locale. man locale for further information.

Hi binlib,

The hexa print out I show in my previous post, I see it in display.

I'm not sure if od command will produce a readable output showing correctly the extended ascii character or how it works.

Thanks for help so far.

---------- Post updated at 06:06 PM ---------- Previous update was at 05:53 PM ----------

Hi fpmurphy,

What I'm confuse is why if I sent the echo script alone the output with extended ascii characters is correct, but when the
echo script is part of a more large script as in my example, in the output the extended ascii characters are not printed.

What is the output of:

locale

Is the script being run by you on the same system?

Hi fpmurphy,

I'm using Cygwin and I'm using the script in a machine with Windows 7 in Spanish.

locale command gives me this output:

$ locale
LANG=C.UTF-8
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_ALL=

Thanks for any help

Grettings