Shell 由格式字符串中的转义字符包围的Hexdump转换字符串

Shell 由格式字符串中的转义字符包围的Hexdump转换字符串,shell,command-line,hexdump,Shell,Command Line,Hexdump,我试图从hextump获得以下结果: 78 79 7a 这是“\t78\t\t79\t\t7a\t” 尝试 echo -n xyz | hexdump -e '1/1 "\t%x\t"' 导致错误: hexdump: % : bad conversion character 但是 正确的产量 |78||79||7a| 添加空格: echo -n xyz | hexdump -e '1/1 "\t %x \t"' 做某事: 这是“\tt 78\t\tt 79

我试图从hextump
获得以下结果:

    78      79      7a
这是
“\t78\t\t79\t\t7a\t”

尝试

echo -n xyz | hexdump -e '1/1 "\t%x\t"'
导致错误:

hexdump: %  : bad conversion character
但是

正确的产量

|78||79||7a|
添加空格:

echo -n xyz | hexdump -e '1/1 "\t %x \t"'
做某事:

这是
“\tt 78\t\tt 79\t\tt 7a\t”
但我得到了所需的制表符和文字字母
t
以及一些不需要的空格字符

当只使用一个尾随选项卡时,它会起作用

echo -n xyz | hexdump -e '1/1 "%x\t"'
给我

78  79  7a  
这是
“78\t79\t7a\t”
,但不适用于单个前导选项卡

echo -n xyz | hexdump -e '1/1 "\t%x"'
这给了我另一个错误

hexdump: %A: bad conversion character
我不确定该错误来自何处,因为任何地方都没有
%A

根据手册页,
\t
应该是一个受支持的转义序列,我将其视为printf中的任何其他字符

格式是必需的,必须用双引号(“”)括起来 标志。它被解释为fprintf样式的格式字符串(请参见 fprintf(3)),但以下情况除外:

 +o   An asterisk (*) may not be used as a field width    or precision.

 +o   A byte count or field precision is required for each ``s'' con-
     version character (unlike the fprintf(3) default which prints
     the entire string if the precision is unspecified).

 +o   The conversion characters ``h'',    ``l'', ``n'', ``p'' and ``q''
     are not supported.

 +o   The single character escape sequences described in the C    stan-
     dard are supported:

      NUL                 \0
      <alert character>   \a
      <backspace>         \b
      <form-feed>         \f
      <newline>           \n
      <carriage return>   \r
      <tab>               \t
      <vertical tab>      \v
+o星号(*)不能用作字段宽度或精度。
+o每个“s”con都需要字节计数或字段精度-
版本字符(与打印的fprintf(3)默认值不同
如果未指定精度,则为整个字符串)。
+o转换字符“h”、“l”、“n”、“p”和“q”
不支持。
+o C标准中描述的单字符转义序列-
支持dard:
NUL\0
\a
\b
\f
\n
\r
\t
\五
这种行为。对于受影响的版本,有一个解决方法:只需将前导反斜杠放入单独的格式字符串中

例如,您想要的代码如下所示:

echo -n xyz | hexdump -e '"\t" 1/1 "%x"'

您的shell是否可能首先尝试扩展单个反斜杠?也就是说,尝试使用双反斜杠。前导
\\t
的错误相同。使用bash时,整个参数都在一个带引号的字符串中,因此它不应该在shell端进行任何扩展。
hextump:%\:两个参数都使用时,转换字符不正确。
\\t%x\\t
 +o   An asterisk (*) may not be used as a field width    or precision.

 +o   A byte count or field precision is required for each ``s'' con-
     version character (unlike the fprintf(3) default which prints
     the entire string if the precision is unspecified).

 +o   The conversion characters ``h'',    ``l'', ``n'', ``p'' and ``q''
     are not supported.

 +o   The single character escape sequences described in the C    stan-
     dard are supported:

      NUL                 \0
      <alert character>   \a
      <backspace>         \b
      <form-feed>         \f
      <newline>           \n
      <carriage return>   \r
      <tab>               \t
      <vertical tab>      \v
echo -n xyz | hexdump -e '"\t" 1/1 "%x"'