Linux 中的扩展 Ascii
我如何在 Linux 中打印这些字符?
│ (ascii 179)
├ (ascii 195)
└ (ascii 192)
─ (ascii 196)
我找不到任何可以与 echo -e "\0xxx" 一起使用的八进制值,有什么想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
经过仔细研究
man printf
和info printf
后,我想我已经让它工作了。基本问题似乎是 bash 有一个内置的 printf 不起作用。而且,不管手册/信息页面怎么说,
\U
不起作用。不过,\u
仍然如此。env printf '\u2502'
给我一个垂直框字符。
After much poring over
man printf
andinfo 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.
如果您有正确的编码器来显示字符,则可以使用您提供的完全相同的代码或扩展 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. :)
因为有些人可能还想知道这个...
请参阅使用 iconv 翻译的行。
要在 Linux/bash 脚本中打印所有 ascii/扩展 ascii 代码 CP437:
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:
将字体切换为 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.
ASCII(发明于 1960 年)实际上是一个 /7/ 位编码标准,因此仅定义了 {0..127} 范围内的字符。
字符 {128..255}(通常)称为“替代页面”,可以按您希望的任何方式进行映射。有许多“标准”映射,其中“CodePage 437”是/曾经是一个流行的选择(感谢 DOS 支持以及 80 年代和 90 年代的“ANSI 艺术家”)。
在 Linux 下,您可以使用
luit
拦截 stdin 和 stdout 并即时转换数据。创建一个合适的演示文件
Hexdump 文件(健全性检查)
正常显示文件
将文件显示为 cp437(根据 OP):
将文件显示为 cp850(作为附加示例):
您也可以只运行
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
Hexdump the file (sanity check)
Display the file normally
Display the file as cp437 (as per OP):
Display the file as cp850 (as an additional example):
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.