Unicode encoding and decoding, OSX 10.13.5.

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Unicode encoding and decoding, OSX 10.13.5.
# 1  
Old 06-25-2018
Unicode encoding and decoding, OSX 10.13.5.

I am struggling here to understand......
The default encoding.
See photo 1.
Why does this NOT work?
Code:
#!/bin/bash
# Code for OSX 10.13.5. default UNICODE encoding.
echo""
echo "The default UTF-8..."
locale
echo""
echo "Change to 8 bit ASCII only..."
LANG="en_GB.US-ASCII"
export LANG="en_GB.US-ASCII"
locale
echo ""
for N in {0..255}
do
	printf '\x'$( printf "%02x" "$N" )
done
echo ""

Runtime result:
Code:
Last login: Mon Jun 25 17:35:20 on ttys000
AMIGA:amiga~> cd ~/Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./Unicode_Locale.sh

The default UTF-8...
LANG="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_CTYPE="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_ALL=

Change to 8 bit ASCII only...
LANG="en_GB.US-ASCII"
LC_COLLATE="en_GB.US-ASCII"
LC_CTYPE="en_GB.US-ASCII"
LC_MESSAGES="en_GB.US-ASCII"
LC_MONETARY="en_GB.US-ASCII"
LC_NUMERIC="en_GB.US-ASCII"
LC_TIME="en_GB.US-ASCII"
LC_ALL=

	


!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
AMIGA:amiga~/Desktop/Code/Shell> _

Now change encoding from terminal preferences to Western ASCII.
See photo 2.
And voila it works.
Code:
#!/bin/bash
echo ""
echo "Default encoding changed to ~ASCII via terminal preferences..."
locale
echo""
for N in {0..255}
do
	printf '\x'$( printf "%02x" "$N" )
done
echo ""

Runtime result:
Code:
Last login: Mon Jun 25 17:42:33 on ttys000
AMIGA:amiga~> cd ~/Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./ASCII_Coding.sh

Default encoding changed to ~ASCII via terminal preferences...
LANG="en_GB.US-ASCII"
LC_COLLATE="en_GB.US-ASCII"
LC_CTYPE="en_GB.US-ASCII"
LC_MESSAGES="en_GB.US-ASCII"
LC_MONETARY="en_GB.US-ASCII"
LC_NUMERIC="en_GB.US-ASCII"
LC_TIME="en_GB.US-ASCII"
LC_ALL=

	


!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ**
AMIGA:amiga~/Desktop/Code/Shell> _

Am I missing something with the soft-coded locale change as opposed to the terminal startup one?
Unicode encoding and decoding, OSX 10.13.5.-default_encodingjpeg
Unicode encoding and decoding, OSX 10.13.5.-ascii_encodingjpeg
# 2  
Old 06-25-2018
Occasionally it's useful to lie about what your terminal is, i.e. LC_ALL="en_GB.US-ASCII" grep filename whatever to speed up grep when you know it won't matter. But changing the environment variable does not change your terminal. The terminal doesn't even have any way to know you changed it, being you changed it in the shell, not any place it has access to.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-26-2018
Thanks Corona688...

I thought that changing LANG would change the DEncoding for code inside a script.
Changing the DEncoding via the Terminal Preferences works a treat but that defeats the object of something I was experimenting with.
Back to the drawing board... <wink>
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

View file encoding then change encoding.

Hi all!! Im using command file -i myfile.xml to validate XML file encoding, but it is just saying regular file . Im expecting / looking an output as UTF8 or ANSI / ASCII Is there command to display the files encoding? Thank you! (2 Replies)
Discussion started by: mrreds
2 Replies

2. Programming

ASN1 decoding error

Hi, fellows i am modifying asn1 schema to be able to decode a file, but i am hitting a error on one of the fields using free online tool asn1-playground. I suspect i need to change type and have tried with IDENTIFIER but it doesn't help...any ideas check the schema and file down , please ... (0 Replies)
Discussion started by: tahchiev01
0 Replies

3. Shell Programming and Scripting

FTP decoding

I am trying to understand a UNIX script which FTPs certain files from a remote location to the local machine. I understand the basic FTP command but the UNIX script uses the following command: ftp -n -i -v > $logftp_trg 2>&1 <<! open $MFX_FTP_SERVER user $MFX_FTP_LOGIN $MFX_FTP_PWD Can anyone... (5 Replies)
Discussion started by: Bhavesh Sharma
5 Replies

4. UNIX for Dummies Questions & Answers

Decoding a string

Hi, If my input string is 3a3b4c then my result should be aaabbbcccc. Please guide me how to achieve this in a bash script. Thanks (18 Replies)
Discussion started by: pandeesh
18 Replies

5. UNIX for Dummies Questions & Answers

URL decoding with awk

The challenge: Decode URL's, i.e. convert %HEX to the corresponding special characters, using only UNIX base utilities, and without having to type out each special character. I have an anonymous C code snippet where the author assigns each hex digit a number from 0 to 16 and then does some... (2 Replies)
Discussion started by: uiop44
2 Replies

6. Shell Programming and Scripting

How to find the file encoding and updating the file encoding?

Hi, I am beginner to Unix. My requirement is to validate the encoding used in the incoming file(csv,txt).If it is encoded with UTF-8 format,then the file should remain as such otherwise i need to chnage the encoding to UTF-8. Please advice me how to proceed on this. (7 Replies)
Discussion started by: cnraja
7 Replies

7. IP Networking

Packet decoding

Hi, wondering if anyone can suggest a tool to me that will let me either cut & paste hex or type it in for packet decoding. I want to be able to decode a packet as done with tcpdump or wireshark, but I want to be able to manually input the hex myself. (2 Replies)
Discussion started by: Breakology
2 Replies

8. Shell Programming and Scripting

decoding commands

hi please can anyone help me in decoding shell commands. i need a way to decode the encrypted shell commands. (8 Replies)
Discussion started by: rochitsharma
8 Replies

9. Programming

How to display unicode characters / unicode string

I have a stream of characters like "\u8BBE\u5907\u7BA1" and i want to display it. I tried following things already without any luck. 1) printf("%s",L("\u8BBE\u5907\u7BA1")); 2) printf("%lc",0x8BBE); 3) setlocale followed by fwide followed by wprintf 4) also changed the local manually... (3 Replies)
Discussion started by: jackdorso
3 Replies

10. Programming

Decoding of Core Dump

Hi ALL, Is it possible to decode the core dumb file to find the error? I get an Memory Core Dumb error with an core file. Regards, P. Prathaban. (3 Replies)
Discussion started by: p_prathaban
3 Replies
Login or Register to Ask a Question