0

Is it possible to print "Extended ASCII Codes " from "http://www.asciitable.com/" in a Terminal.app bash script ?

What I tried

$ LC_ALL=en_GB.UTF-8 env printf '\u2502'
u2502
$

Specifically I'm trying to print the "LIGHT SHADE" character mentioned in http://www.alanflavell.org.uk/unicode/unidata25.html

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80
  • 1
    FYI, "ASCII" is not the right term for any of this. – Josh Lee Dec 19 '17 at 16:47
  • I was playing with box-drawing characters etc in my answer to [SO 4747-6170](https://stackoverflow.com/questions/47476170). You can find the scripts I used in GitHub in my [SOQ](https://github.com/jleffler/soq/tree/master/src/so-4747-6170) repository. For example, you could run `sh tabulate.sh tab-example.2` to get boxed output from a data file. The `fmt-tabulate.awk` script actually contains the box characters, but you'll see I simply embedded the character in the script. In your context, I'd use a variable setting such as `light_shade="░"`. I'm not sure whether that helps. – Jonathan Leffler Dec 19 '17 at 17:51

1 Answers1

0

The \uHHHH and \UHHHHHHHH escape codes for echo, printf, and $'' are new in Bash 4.2. MacOS ships with Bash 3.2.

You could encode the character directly in your script: printf '│░'. The only difference is your script wouldn't automatically write the characters in the target charset, but would be hardcoded in UTF-8.

Depending on your portability requirements, you could also install a modern version of Bash, and GNU Coreutils, using homebrew.

~$ brew install coreutils
~$ PATH=$(brew --prefix coreutils)/libexec/gnubin/:$PATH 
~$ env printf '\U0001f4a9'
~$ 
Josh Lee
  • 171,072
  • 38
  • 269
  • 275
  • I think it should be handled in printf, not in bash. – n. m. could be an AI Dec 19 '17 at 17:15
  • @n.m. If you don't specify that you want /usr/bin/printf then you'll get bash's printf. Besides, /usr/bin/printf on Mac doesn't implement `\u` either. – Josh Lee Dec 19 '17 at 17:44
  • Unicode handling requires encoding support which lies outside the POSIX standard. You can, however, hardcode the UTF-8 encoding, which any POSIX-compliant `printf` can handle. Whether it *displays* as desired is terminal-dependent, of course. `printf '\342\226\221\n'` – chepner Dec 19 '17 at 18:13
  • Don't think `env` knows about bash printf. Pity /usr/bin/printf is broken too. – n. m. could be an AI Dec 19 '17 at 18:13