Android mksh的替代品';什么是printf?

Android mksh的替代品';什么是printf?,android,sh,Android,Sh,我正在编写一个shell脚本,在Android的mksh上运行。在Bash中,我可以执行以下操作: printf -v NUMBER "%d" \'"$CHARACTER" 上面的命令将$字符转换为有符号十进制数。但mksh不支持printf。是否有只使用mksh/ksh内部命令的替代解决方案?在一定程度上支持,但不推荐使用 为了让mksh使用内置printf,需要使用printf.c构建mksh,并且需要设置生成环境变量use\u printf\u builtin=1,这是不推荐的。然后它将

我正在编写一个shell脚本,在Android的mksh上运行。在Bash中,我可以执行以下操作:

printf -v NUMBER "%d" \'"$CHARACTER"
上面的命令将$字符转换为有符号十进制数。但mksh不支持printf。是否有只使用mksh/ksh内部命令的替代解决方案?

在一定程度上支持,但不推荐使用


为了让mksh使用内置printf,需要使用printf.c构建mksh,并且需要设置生成环境变量use\u printf\u builtin=1,这是不推荐的。然后它将有printf。如果您计划分发此文件,使其可移植,那么这可能不是您想要做的。相反,我会使用更安全的“busybox printf”。大多数设备都有busybox,但要真正使脚本可移植,您需要使用mksh的“打印”功能

 print [-nprsu[n] | -R [-en]] [argument ...]
        print prints its arguments on the standard output, separated by
        spaces and terminated with a newline. The -n option suppresses the
        newline. By default, certain C escapes are translated. These in-
        clude these mentioned in Backslash expansion above, as well as
        '\c', which is equivalent to using the -n option. Backslash expan-
        sion may be inhibited with the -r option. The -s option prints to
        the history file instead of standard output; the -u option prints
        to file descriptor n (n defaults to 1 if omitted); and the -p op-
        tion prints to the co-process (see Co-processes above).

        The -R option is used to emulate, to some degree, the BSD echo(1)
        command which does not process '\' sequences unless the -e option
        is given. As above, the -n option suppresses the trailing newline.

 printf format [arguments ...]
        Formatted output. Approximately the same as the printf(1), utili-
        ty, except it uses the same Backslash expansion and I/O code and
        does hot handle floating point as the rest of mksh. This is not
        normally part of mksh; however, distributors may have added this
        as builtin as a speed hack. Do not use in new code.