OS X (Apple)

OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple.

Unicode encoding and decoding, OSX 10.13.5.

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 3 Weeks Ago
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 18 July 2018, 12:17 PM EDT
Location: Loughborough
Posts: 1,290
Thanks: 388
Thanked 352 Times in 277 Posts
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?
Attached Thumbnails
Unicode encoding and decoding, OSX 10.13.5.-default_encoding-jpeg   Unicode encoding and decoding, OSX 10.13.5.-ascii_encoding-jpeg  
Sponsored Links
    #2  
Old 3 Weeks Ago
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 18 July 2018, 1:08 PM EDT
Location: Saskatchewan
Posts: 22,724
Thanks: 1,193
Thanked 4,350 Times in 4,005 Posts
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.
The Following User Says Thank You to Corona688 For This Useful Post:
wisecracker (3 Weeks Ago)
Sponsored Links
    #3  
Old 3 Weeks Ago
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 18 July 2018, 12:17 PM EDT
Location: Loughborough
Posts: 1,290
Thanks: 388
Thanked 352 Times in 277 Posts
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>
Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
View file encoding then change encoding. mrreds Solaris 2 01-13-2018 03:19 PM
FTP decoding Bhavesh Sharma Shell Programming and Scripting 5 06-25-2014 08:31 PM
Decoding a string pandeesh UNIX for Dummies Questions & Answers 18 03-19-2012 06:38 AM
How to find the file encoding and updating the file encoding? cnraja Shell Programming and Scripting 7 05-27-2011 06:50 AM
How to display unicode characters / unicode string jackdorso Programming 3 05-20-2005 01:09 PM



All times are GMT -4. The time now is 06:26 PM.

Unix & Linux Forums Content Copyright1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?