Linux 中的扩展 Ascii

发布于 2024-10-31 04:50:49 字数 170 浏览 1 评论 0 原文

我如何在 Linux 中打印这些字符?

│ (ascii 179)

├ (ascii 195)

└ (ascii 192)

─ (ascii 196)

我找不到任何可以与 echo -e "\0xxx" 一起使用的八进制值,有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浮云落日 2024-11-07 04:50:49

经过仔细研究 man printfinfo printf 后,我想我已经让它工作了。

基本问题似乎是 bash 有一个内置的 printf 不起作用。而且,不管手册/信息页面怎么说, \U 不起作用。不过,\u 仍然如此。

env printf '\u2502'

给我一个垂直框字符。

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.

满地尘埃落定 2024-11-07 04:50:49

如果您有正确的编码器来显示字符,则可以使用您提供的完全相同的代码或扩展 ASCII 字符集的代码(例如 195 表示 ├)。

在 Linux 上,我们缺乏非标准扩展 ASCII 字符集支持 - 这就是它不显示的原因。不过,我发现了另一种可用于 Linux 的字符集,并且几乎与扩展 ASCII 字符集相似。这是IBM855。

您所要做的就是将命令行应用程序的字符编码更改为 IBM855。所有流行的方框图字符都具有相同的扩展 ASCII 字符集代码 - 这是最重要的。

您可以通过此图像和此图像

PS:如果您使用的是 gnome-terminal,您可以通过单击菜单栏上的“Terminal”菜单 -> 添加 IBM855 字符集“设置字符编码”-> “添加或删除”。查找IBM855,然后添加它。现在只需从“终端”->“设置字符编码”->“西里尔字母(IBM855)”中选择编码即可。

这些盒子足够我做作业了。希望这有帮助。 :)

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. :)

愛放△進行李 2024-11-07 04:50:49

因为有些人可能还想知道这个...

请参阅使用 iconv 翻译的行。

要在 Linux/bash 脚本中打印所有 ascii/扩展 ascii 代码 CP437:

# 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

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

御守 2024-11-07 04:50:49

将字体切换为 PC-8/CP437 编码的字体,或者使用这些字符的 Unicode 值,编码到当前字符集中。

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.

若相惜即相离 2024-11-07 04:50:49

ASCII(发明于 1960 年)实际上是一个 /7/ 位编码标准,因此仅定义了 {0..127} 范围内的字符。

字符 {128..255}(通常)称为“替代页面”,可以按您希望的任何方式进行映射。有许多“标准”映射,其中“CodePage 437”是/曾经是一个流行的选择(感谢 DOS 支持以及 80 年代和 90 年代的“ANSI 艺术家”)。

在 Linux 下,您可以使用 luit 拦截 stdin 和 stdout 并即时转换数据。

创建一个合适的演示文件

(for i in `seq 128 255` ; do printf "\x$(printf "%02x" $i)" ; done; echo) >demo.txt

Hexdump 文件(健全性检查)

hexdump -C demo.txt

正常显示文件

cat demo.txt

将文件显示为 cp437(根据 OP):

luit -encoding cp437 cat demo.txt

将文件显示为 cp850(作为附加示例):

luit -encoding cp850 cat demo.txt

您也可以只运行 luit -encoding cp437 打开一个使用 cp437 编码的子 shell(使用 ^D 退出 luit),此时您的 [OP] echo 语句应该按需要工作。

ASCII (invented in 1960) is actually a /seven/ bit encoding standard, and as such only the characters in the range {0..127} are defined.

Characters {128..255} are (commonly) referred to as the "alt page" and can be mapped any way you wish. There are MANY "standard" mappings, of which "CodePage 437" is/was a popular choice (thanks to DOS support, and "ANSI artists" of the 80s and 90s).

Under Linux, you can use luit to intercept stdin and stdout and convert data on the fly.

Create a suitable demo file

(for i in `seq 128 255` ; do printf "\x$(printf "%02x" $i)" ; done; echo) >demo.txt

Hexdump the file (sanity check)

hexdump -C demo.txt

Display the file normally

cat demo.txt

Display the file as cp437 (as per OP):

luit -encoding cp437 cat demo.txt

Display the file as cp850 (as an additional example):

luit -encoding cp850 cat demo.txt

You can also just run luit -encoding cp437 to open a sub-shell with cp437 encoding (use ^D to exit luit), at which point your [OP] echo statements should work as desired.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文