"M- notation" 是什么,它记录在哪里?
What is the "M- notation" and where is it documented?
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
什么是 M-
表示法,它在哪里记录?
示例:
$cat log -A
wrote 262144 bytes from file test.x in 9.853947s (25.979 KiB/s)^M$
^M> ^H^H ^H^H>
^M
和 ^H
是什么意思?
^M
用于 Control-M(回车 return),^H
用于 Control-H(退格)。 M-Something
是 Meta-Something(Meta- 是 Alt 键在某些终端中的作用)。
我也在想这个。我检查了源代码,但创建一个输入文件来获取映射似乎更容易。
我用 Perl 脚本 for( my $i=0 ; $i < 256; $i++ ) { print ( sprintf( "%c is %d %x\n", $i, $i ,$i ) ); }
创建了一个测试输入文件,然后 运行 通过 cat -v
另外,如果您看到 M-oM-;M-?在文件的开头是 UTF-8 字节顺序标记。
向下滚动查看 M 值:
^@ is 0 0
^A is 1 1
^B is 2 2
^C is 3 3
^D is 4 4
^E is 5 5
^F is 6 6
^G is 7 7
^H is 8 8
(9 is tab)
(10 is NL)
^K is 11 b
^L is 12 c
^M is 13 d
^N is 14 e
^O is 15 f
^P is 16 10
^Q is 17 11
^R is 18 12
^S is 19 13
^T is 20 14
^U is 21 15
^V is 22 16
^W is 23 17
^X is 24 18
^Y is 25 19
^Z is 26 1a
^[ is 27 1b
^\ is 28 1c
^] is 29 1d
^^ is 30 1e
^_ is 31 1f
...printing chars removed...
^? is 127 7f
M-^@ is 128 80
M-^A is 129 81
M-^B is 130 82
M-^C is 131 83
M-^D is 132 84
M-^E is 133 85
M-^F is 134 86
M-^G is 135 87
M-^H is 136 88
M-^I is 137 89
M-^J is 138 8a
M-^K is 139 8b
M-^L is 140 8c
M-^M is 141 8d
M-^N is 142 8e
M-^O is 143 8f
M-^P is 144 90
M-^Q is 145 91
M-^R is 146 92
M-^S is 147 93
M-^T is 148 94
M-^U is 149 95
M-^V is 150 96
M-^W is 151 97
M-^X is 152 98
M-^Y is 153 99
M-^Z is 154 9a
M-^[ is 155 9b
M-^\ is 156 9c
M-^] is 157 9d
M-^^ is 158 9e
M-^_ is 159 9f
M- is 160 a0
M-! is 161 a1
M-" is 162 a2
M-# is 163 a3
M-$ is 164 a4
M-% is 165 a5
M-& is 166 a6
M-' is 167 a7
M-( is 168 a8
M-) is 169 a9
M-* is 170 aa
M-+ is 171 ab
M-, is 172 ac
M-- is 173 ad
M-. is 174 ae
M-/ is 175 af
M-0 is 176 b0
M-1 is 177 b1
M-2 is 178 b2
M-3 is 179 b3
M-4 is 180 b4
M-5 is 181 b5
M-6 is 182 b6
M-7 is 183 b7
M-8 is 184 b8
M-9 is 185 b9
M-: is 186 ba
M-; is 187 bb
M-< is 188 bc
M-= is 189 bd
M-> is 190 be
M-? is 191 bf
M-@ is 192 c0
M-A is 193 c1
M-B is 194 c2
M-C is 195 c3
M-D is 196 c4
M-E is 197 c5
M-F is 198 c6
M-G is 199 c7
M-H is 200 c8
M-I is 201 c9
M-J is 202 ca
M-K is 203 cb
M-L is 204 cc
M-M is 205 cd
M-N is 206 ce
M-O is 207 cf
M-P is 208 d0
M-Q is 209 d1
M-R is 210 d2
M-S is 211 d3
M-T is 212 d4
M-U is 213 d5
M-V is 214 d6
M-W is 215 d7
M-X is 216 d8
M-Y is 217 d9
M-Z is 218 da
M-[ is 219 db
M-\ is 220 dc
M-] is 221 dd
M-^ is 222 de
M-_ is 223 df
M-` is 224 e0
M-a is 225 e1
M-b is 226 e2
M-c is 227 e3
M-d is 228 e4
M-e is 229 e5
M-f is 230 e6
M-g is 231 e7
M-h is 232 e8
M-i is 233 e9
M-j is 234 ea
M-k is 235 eb
M-l is 236 ec
M-m is 237 ed
M-n is 238 ee
M-o is 239 ef
M-p is 240 f0
M-q is 241 f1
M-r is 242 f2
M-s is 243 f3
M-t is 244 f4
M-u is 245 f5
M-v is 246 f6
M-w is 247 f7
M-x is 248 f8
M-y is 249 f9
M-z is 250 fa
M-{ is 251 fb
M-| is 252 fc
M-} is 253 fd
M-~ is 254 fe
M-^? is 255 ff
我不确定 M-
表示法,但涉及 ^
的表示法使用 caret notation:
Caret notation is a notation for control characters in ASCII.
特别是,
The digraph stands for the control character whose ASCII code is the
same as the character's ASCII code with the uppermost bit, in a 7-bit
encoding, reversed.
您可以通过查看 ASCII 二进制(八进制)表示来验证:
图片来源:http://www.asciitable.com
因为 ASCII 是一个非常有限的字符集(正如您在上面看到的),所以很容易列出所有由插入符号表示的控制字符,例如 http://xahlee.info/comp/unicode_character_representation.html.
中看到定义
Likewise, the meta
(3X) function allows the caller to change the output of keyname
, i.e., it determines whether to use the “M-” prefix for “meta” keys (codes in the range 128 to 255). Both use_legacy_coding
(3X) and meta
(3X) succeed only after curses is initialized. X/Open Curses does not document the treatment of codes 128 to 159. When treating them as “meta” keys (or if keyname
is called before initializing curses), this implementation returns strings “M-^@”
, “M-^A”
, etc.
所以基本上 Meta 模拟 Ctrl 版本是 Ctrl + 128[=39= 的键码].您可以在 Brian 的 table 中轻松看到这一点。为了便于比较,这里有一个稍微修改过的版本
$ LC_ALL=C perl -e 'for( my $i=0 ; $i < 128; $i++ ) {
print ( sprintf( "%c is %d %x\t\t%c is %d %x\n",
$i, $i, $i, $i + 128, $i + 128, $i + 128 ) );
}' >bytes.txt
$ cat -v bytes.txt
^@ is 0 0 M-^@ is 128 80
^A is 1 1 M-^A is 129 81
^B is 2 2 M-^B is 130 82
^C is 3 3 M-^C is 131 83
...
^Y is 25 19 M-^Y is 153 99
^Z is 26 1a M-^Z is 154 9a
^[ is 27 1b M-^[ is 155 9b
^\ is 28 1c M-^\ is 156 9c
^] is 29 1d M-^] is 157 9d
^^ is 30 1e M-^^ is 158 9e
^_ is 31 1f M-^_ is 159 9f
is 32 20 M- is 160 a0
! is 33 21 M-! is 161 a1
" is 34 22 M-" is 162 a2
# is 35 23 M-# is 163 a3
$ is 36 24 M-$ is 164 a4
% is 37 25 M-% is 165 a5
& is 38 26 M-& is 166 a6
' is 39 27 M-' is 167 a7
( is 40 28 M-( is 168 a8
) is 41 29 M-) is 169 a9
* is 42 2a M-* is 170 aa
+ is 43 2b M-+ is 171 ab
, is 44 2c M-, is 172 ac
- is 45 2d M-- is 173 ad
. is 46 2e M-. is 174 ae
/ is 47 2f M-/ is 175 af
0 is 48 30 M-0 is 176 b0
1 is 49 31 M-1 is 177 b1
...
: is 58 3a M-: is 186 ba
; is 59 3b M-; is 187 bb
< is 60 3c M-< is 188 bc
= is 61 3d M-= is 189 bd
> is 62 3e M-> is 190 be
? is 63 3f M-? is 191 bf
@ is 64 40 M-@ is 192 c0
A is 65 41 M-A is 193 c1
B is 66 42 M-B is 194 c2
...
Z is 90 5a M-Z is 218 da
[ is 91 5b M-[ is 219 db
\ is 92 5c M-\ is 220 dc
] is 93 5d M-] is 221 dd
^ is 94 5e M-^ is 222 de
_ is 95 5f M-_ is 223 df
` is 96 60 M-` is 224 e0
a is 97 61 M-a is 225 e1
b is 98 62 M-b is 226 e2
...
z is 122 7a M-z is 250 fa
{ is 123 7b M-{ is 251 fb
| is 124 7c M-| is 252 fc
} is 125 7d M-} is 253 fd
~ is 126 7e M-~ is 254 fe
^? is 127 7f M-^? is 255 ff
右边M-
后的部分和左边完全一样,键码相差128
你也可以查看cat's source code,在show_nonprinting
情况
中Meta key版本的基本表达式是*bpout++ = ch - 128;
书中的答案。
Unix 强大的工具。
25.7 使用 cat -v 或 od -c.
显示 Non-Printing 个字符
"cat -v 对 ASCII 范围外的字符有自己的符号,并设置了高位,也称为元字符。cat -v 将它们打印为 M- 后跟另一个字符。其中有两个在 cat -v output: M-^? and M-a .要得到一个元字符,你加200个八进制。“说什么?”我们先看M-a,字母a的八进制值为141。 cat -v 打印出 M-a 时,表示141+200相加得到的字符,也就是八进制的341。同理可以将cat打印出的字符解码为M-^?,其中^?代表DEL字符,八进制为177,200+177相加,八进制为377。"
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
什么是 M-
表示法,它在哪里记录?
示例:
$cat log -A
wrote 262144 bytes from file test.x in 9.853947s (25.979 KiB/s)^M$
^M> ^H^H ^H^H>
^M
和 ^H
是什么意思?
^M
用于 Control-M(回车 return),^H
用于 Control-H(退格)。 M-Something
是 Meta-Something(Meta- 是 Alt 键在某些终端中的作用)。
我也在想这个。我检查了源代码,但创建一个输入文件来获取映射似乎更容易。
我用 Perl 脚本 for( my $i=0 ; $i < 256; $i++ ) { print ( sprintf( "%c is %d %x\n", $i, $i ,$i ) ); }
创建了一个测试输入文件,然后 运行 通过 cat -v
另外,如果您看到 M-oM-;M-?在文件的开头是 UTF-8 字节顺序标记。
向下滚动查看 M 值:
^@ is 0 0
^A is 1 1
^B is 2 2
^C is 3 3
^D is 4 4
^E is 5 5
^F is 6 6
^G is 7 7
^H is 8 8
(9 is tab)
(10 is NL)
^K is 11 b
^L is 12 c
^M is 13 d
^N is 14 e
^O is 15 f
^P is 16 10
^Q is 17 11
^R is 18 12
^S is 19 13
^T is 20 14
^U is 21 15
^V is 22 16
^W is 23 17
^X is 24 18
^Y is 25 19
^Z is 26 1a
^[ is 27 1b
^\ is 28 1c
^] is 29 1d
^^ is 30 1e
^_ is 31 1f
...printing chars removed...
^? is 127 7f
M-^@ is 128 80
M-^A is 129 81
M-^B is 130 82
M-^C is 131 83
M-^D is 132 84
M-^E is 133 85
M-^F is 134 86
M-^G is 135 87
M-^H is 136 88
M-^I is 137 89
M-^J is 138 8a
M-^K is 139 8b
M-^L is 140 8c
M-^M is 141 8d
M-^N is 142 8e
M-^O is 143 8f
M-^P is 144 90
M-^Q is 145 91
M-^R is 146 92
M-^S is 147 93
M-^T is 148 94
M-^U is 149 95
M-^V is 150 96
M-^W is 151 97
M-^X is 152 98
M-^Y is 153 99
M-^Z is 154 9a
M-^[ is 155 9b
M-^\ is 156 9c
M-^] is 157 9d
M-^^ is 158 9e
M-^_ is 159 9f
M- is 160 a0
M-! is 161 a1
M-" is 162 a2
M-# is 163 a3
M-$ is 164 a4
M-% is 165 a5
M-& is 166 a6
M-' is 167 a7
M-( is 168 a8
M-) is 169 a9
M-* is 170 aa
M-+ is 171 ab
M-, is 172 ac
M-- is 173 ad
M-. is 174 ae
M-/ is 175 af
M-0 is 176 b0
M-1 is 177 b1
M-2 is 178 b2
M-3 is 179 b3
M-4 is 180 b4
M-5 is 181 b5
M-6 is 182 b6
M-7 is 183 b7
M-8 is 184 b8
M-9 is 185 b9
M-: is 186 ba
M-; is 187 bb
M-< is 188 bc
M-= is 189 bd
M-> is 190 be
M-? is 191 bf
M-@ is 192 c0
M-A is 193 c1
M-B is 194 c2
M-C is 195 c3
M-D is 196 c4
M-E is 197 c5
M-F is 198 c6
M-G is 199 c7
M-H is 200 c8
M-I is 201 c9
M-J is 202 ca
M-K is 203 cb
M-L is 204 cc
M-M is 205 cd
M-N is 206 ce
M-O is 207 cf
M-P is 208 d0
M-Q is 209 d1
M-R is 210 d2
M-S is 211 d3
M-T is 212 d4
M-U is 213 d5
M-V is 214 d6
M-W is 215 d7
M-X is 216 d8
M-Y is 217 d9
M-Z is 218 da
M-[ is 219 db
M-\ is 220 dc
M-] is 221 dd
M-^ is 222 de
M-_ is 223 df
M-` is 224 e0
M-a is 225 e1
M-b is 226 e2
M-c is 227 e3
M-d is 228 e4
M-e is 229 e5
M-f is 230 e6
M-g is 231 e7
M-h is 232 e8
M-i is 233 e9
M-j is 234 ea
M-k is 235 eb
M-l is 236 ec
M-m is 237 ed
M-n is 238 ee
M-o is 239 ef
M-p is 240 f0
M-q is 241 f1
M-r is 242 f2
M-s is 243 f3
M-t is 244 f4
M-u is 245 f5
M-v is 246 f6
M-w is 247 f7
M-x is 248 f8
M-y is 249 f9
M-z is 250 fa
M-{ is 251 fb
M-| is 252 fc
M-} is 253 fd
M-~ is 254 fe
M-^? is 255 ff
我不确定 M-
表示法,但涉及 ^
的表示法使用 caret notation:
Caret notation is a notation for control characters in ASCII.
特别是,
The digraph stands for the control character whose ASCII code is the same as the character's ASCII code with the uppermost bit, in a 7-bit encoding, reversed.
您可以通过查看 ASCII 二进制(八进制)表示来验证:
因为 ASCII 是一个非常有限的字符集(正如您在上面看到的),所以很容易列出所有由插入符号表示的控制字符,例如 http://xahlee.info/comp/unicode_character_representation.html.
Likewise, the
meta
(3X) function allows the caller to change the output ofkeyname
, i.e., it determines whether to use the “M-” prefix for “meta” keys (codes in the range 128 to 255). Bothuse_legacy_coding
(3X) andmeta
(3X) succeed only after curses is initialized. X/Open Curses does not document the treatment of codes 128 to 159. When treating them as “meta” keys (or ifkeyname
is called before initializing curses), this implementation returns strings“M-^@”
,“M-^A”
, etc.
所以基本上 Meta 模拟 Ctrl 版本是 Ctrl + 128[=39= 的键码].您可以在 Brian 的 table 中轻松看到这一点。为了便于比较,这里有一个稍微修改过的版本
$ LC_ALL=C perl -e 'for( my $i=0 ; $i < 128; $i++ ) {
print ( sprintf( "%c is %d %x\t\t%c is %d %x\n",
$i, $i, $i, $i + 128, $i + 128, $i + 128 ) );
}' >bytes.txt
$ cat -v bytes.txt
^@ is 0 0 M-^@ is 128 80
^A is 1 1 M-^A is 129 81
^B is 2 2 M-^B is 130 82
^C is 3 3 M-^C is 131 83
...
^Y is 25 19 M-^Y is 153 99
^Z is 26 1a M-^Z is 154 9a
^[ is 27 1b M-^[ is 155 9b
^\ is 28 1c M-^\ is 156 9c
^] is 29 1d M-^] is 157 9d
^^ is 30 1e M-^^ is 158 9e
^_ is 31 1f M-^_ is 159 9f
is 32 20 M- is 160 a0
! is 33 21 M-! is 161 a1
" is 34 22 M-" is 162 a2
# is 35 23 M-# is 163 a3
$ is 36 24 M-$ is 164 a4
% is 37 25 M-% is 165 a5
& is 38 26 M-& is 166 a6
' is 39 27 M-' is 167 a7
( is 40 28 M-( is 168 a8
) is 41 29 M-) is 169 a9
* is 42 2a M-* is 170 aa
+ is 43 2b M-+ is 171 ab
, is 44 2c M-, is 172 ac
- is 45 2d M-- is 173 ad
. is 46 2e M-. is 174 ae
/ is 47 2f M-/ is 175 af
0 is 48 30 M-0 is 176 b0
1 is 49 31 M-1 is 177 b1
...
: is 58 3a M-: is 186 ba
; is 59 3b M-; is 187 bb
< is 60 3c M-< is 188 bc
= is 61 3d M-= is 189 bd
> is 62 3e M-> is 190 be
? is 63 3f M-? is 191 bf
@ is 64 40 M-@ is 192 c0
A is 65 41 M-A is 193 c1
B is 66 42 M-B is 194 c2
...
Z is 90 5a M-Z is 218 da
[ is 91 5b M-[ is 219 db
\ is 92 5c M-\ is 220 dc
] is 93 5d M-] is 221 dd
^ is 94 5e M-^ is 222 de
_ is 95 5f M-_ is 223 df
` is 96 60 M-` is 224 e0
a is 97 61 M-a is 225 e1
b is 98 62 M-b is 226 e2
...
z is 122 7a M-z is 250 fa
{ is 123 7b M-{ is 251 fb
| is 124 7c M-| is 252 fc
} is 125 7d M-} is 253 fd
~ is 126 7e M-~ is 254 fe
^? is 127 7f M-^? is 255 ff
右边M-
后的部分和左边完全一样,键码相差128
你也可以查看cat's source code,在show_nonprinting
情况
*bpout++ = ch - 128;
书中的答案。
Unix 强大的工具。 25.7 使用 cat -v 或 od -c.
显示 Non-Printing 个字符"cat -v 对 ASCII 范围外的字符有自己的符号,并设置了高位,也称为元字符。cat -v 将它们打印为 M- 后跟另一个字符。其中有两个在 cat -v output: M-^? and M-a .要得到一个元字符,你加200个八进制。“说什么?”我们先看M-a,字母a的八进制值为141。 cat -v 打印出 M-a 时,表示141+200相加得到的字符,也就是八进制的341。同理可以将cat打印出的字符解码为M-^?,其中^?代表DEL字符,八进制为177,200+177相加,八进制为377。"