Preserve extented ascii character when run echo comand inside bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Preserve extented ascii character when run echo comand inside bash script
# 1  
Old 10-29-2011
Preserve extented ascii character when run echo command inside bash script

Hi everyone,

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

Code:
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
Code:
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:
Code:
#!/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

Last edited by Ophiuchus; 10-29-2011 at 06:55 AM..
# 2  
Old 10-29-2011
Do a dump of output4 with
Code:
od -t x1 output4

# 3  
Old 10-29-2011
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:
Code:
$ 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
# 4  
Old 10-29-2011
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.
# 5  
Old 10-29-2011
You need to change your locale to a french locale. man locale for further information.
# 6  
Old 10-29-2011
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 ----------

Quote:
Originally Posted by fpmurphy
You need to change your locale to a french locale. man locale for further information.
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.
# 7  
Old 10-30-2011
Quote:
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:
Code:
locale

Is the script being run by you on the same system?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

2. Shell Programming and Scripting

Run bash command inside zsh script

Hi, I would like to run following code in bash inside a zsh script. (In this case is output unfortunately very different if you run it in zsh). I tried to put "bash" in front of the code but I obtained following error message "bash: do: No such file or directory " eve though I merged the whole... (7 Replies)
Discussion started by: kamcamonty
7 Replies

3. Shell Programming and Scripting

Preserve spaces while reading character character

Hi All, I am trying to read a file character by character, #!/bin/bash while read -n1 char; do echo -e "$char\c" done < /home/shak/testprogram/words Newyork is a very good city. Newyorkisaverygoodcityforliving I need to preserve the spaces as thats an... (3 Replies)
Discussion started by: Kingcobra
3 Replies

4. Shell Programming and Scripting

Preserve commas inside double quotes (perl)

Hi, I have an input file like this $ cat infile hi,i,"am , sam", y hello ,good, morning abcd, " ef, gh " ,ij no, "good,morning", yes, "good , afternoon" from this file I have to split the fields on basis of comma"," however, I the data present inside double qoutes should be treated as... (3 Replies)
Discussion started by: sam05121988
3 Replies

5. Shell Programming and Scripting

Preserve value between different run of script.

I have a script that test for server up status. I need to preserve the value of status between every run of the script. test.sh log=$(cat /tmp/log_status) start loop test for servers print status for munin etc test=$(echo -e "${test}${status},") end loop echo $test >... (4 Replies)
Discussion started by: Jotne
4 Replies

6. Shell Programming and Scripting

Bash- Command run from script does not pass full parameters with spaces inside

There's a JavaScript file that I call from command line (there's a framework) like so: ./RunDiag.js param1:'string one here' param2:'string two here' I have a shell script where I invoke the above command. I can run it in a script as simple as this #!/bin/bash stuff="./RunDiag.js... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

7. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

8. UNIX for Advanced & Expert Users

Processing extended ascii character file names in UNIX (BASH scipts)

Hi, I have a accentuated letter (ö) in a script for an Installer. It's a file name. This is not working and I'm told to try using the octal value for the extended ascii character. Does anyone no how to do this? If I had the word "filförval", can I just put in the value between the letters, like... (9 Replies)
Discussion started by: peli
9 Replies

9. Shell Programming and Scripting

Problem in executing a comand liying inside a variable

Hi everyone! I need some help with my shell script :( I am sending a shell command from a html text input to a cgi. Then, I store it into a variable. For example var="ps -axu" echo `$var` This functions properly. But consider the following... var="ps -axu | grep root" Now, I want... (2 Replies)
Discussion started by: Nene
2 Replies

10. UNIX for Advanced & Expert Users

run a shell script with echo

I need to schedule a shell script that runs at the command prompt to run with crontab. When I run this at the command prompt as follows it works: echo /usr/test/script.sh date1 date2 y | at 20:00 But if I will pass these argument (date1, date2, Y) with in a shell script (say scr1.sh) and... (7 Replies)
Discussion started by: keerthi
7 Replies
Login or Register to Ask a Question