How would I print these characters in Linux?
│ (ascii 179)
├ (ascii 195)
└ (ascii 192)
─ (ascii 196)
I cannot find any octal values that would work with echo -e "\0xxx", any ideas?
On a standard 101 keyboard, special extended ASCII characters such as é or ß can be typed by holding the ALT key and typing the corresponding 4 digit ASCII code. For example é is typed by holding the ALT key and typing 0233 on the keypad.
Extended ASCII is a version that supports representation of 256 different characters. This is because extended ASCII uses eight bits to represent a character as opposed to seven in standard ASCII (where the 8th bit is used for error checking).
Extended-ASCII, with numeric code points between 128 to 255 decimal (80 to FF hexadecimal, 1000 0000 to 1111 1111 binary), collides with UTF-8 because it has the leftmost bit set to one, and this tells the interpreter that one (at least one) additional byte is required to form the character.
ASCII originally used seven bits to encode each character. This was later increased to eight with Extended ASCII to address the apparent inadequacy of the original. In contrast, Unicode uses a variable bit encoding program where you can choose between 32, 16, and 8-bit encodings.
After much poring over man printf
and info printf
, I think I've gotten this to work.
The basic issue seems to be that bash has a built-in printf
that doesn't work. And, despite what the man/info pages, say, \U
doesn't work. \u
still does, though.
env printf '\u2502'
gets me a vertical box character.
You can use the exact same codes you provided or of the extended ASCII character set (e.g. 195 for ├) if you've got the right encoder to display the characters.
On Linux, we lack the non-standard extended ASCII character set support - which is why it's not displayed. However, I found another character set that's available for Linux and is almost similar to the extended ASCII character set. It's IBM855.
All you have to do is changed the character encoding of your command line application to IBM855. All popular box drawing characters have the same code of the extended ASCII character set - which is the most important.
You may compare the sets by this image and this image.
PS: If you're using gnome-terminal, you can add IBM855 charset by clicking the "Terminal" menu from the menu bar -> "set character encoding" -> "Add or Remove". Look for IBM855, and add it. Now just choose the encoding from "terminal"->"set character encoding"->"Cyrillic (IBM855)".
They boxes were enough for my homework. Hope this helps. :)
Either switch the font to one that is in PC-8/CP437 encoding, or use the Unicode values for those characters instead, encoded into the current charset.
Because some people may still want to know this...
See the lines that uses iconv to translate.
To print all ascii/extended ascii codes CP437 in Linux/bash script:
# heading index with div line
printf "\n "; # indent
for x in {0..15}; do printf "%-3x" $x; done;
printf "\n%46s\n" | sed 's/ /-/g;s/^/ /';
# two lines with dots to represent control chars
c=$(echo "fa" | xxd -p -r | iconv -f 'CP437//' -t 'UTF-8')
printf "%32s" | sed 's/../'"$c"' /g;s/^/ 0 /;s/$/\n\n/'
printf "%32s" | sed 's/../'"$c"' /g;s/^/ 1 /'
# convert dec to codepage 437 in a table
for x in {32..255};
do
# newline every 16 translated code values
(( x % 16 == 0 )) && printf "\n\n"
# left index numbers
let "n = x % 15"
(( (x % 16) == 0 )) && printf "%-4x" $n | sed 's/0/f/;s/^/ /'
# conversion of x integer value to symbol
printf "%02x" $x | xxd -p -r | iconv -f 'CP437//' -t 'UTF-8' | sed 's/.*/& /'
# div line
(( x == 127 )) && printf "%46s" | sed 's/ /-/g;s/^/ /;i\ '
done
printf "%46s" | sed 's/ /-/g;s/^/\n /;s/$/\n /'; # div line
for x in {0..15}; do printf "%-3x" $x; done;
echo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With