perl和bash变量替换,带有十六进制字符和重复计数 [英] perl and bash variable substitution, with hexadecimal characters and repeat count
本文介绍了perl和bash变量替换,带有十六进制字符和重复计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
alex@d120432:~$ echo $0
bash
alex@d120432:~$ perl -e 'print "\x41\x42\x43\x44\x0a"x2'
ABCD
ABCD
alex@d120432:~$ i=2
alex@d120432:~$ echo $i
2
alex@d120432:~$ perl -e 'print "\x41\x42\x43\x44\x0a" x $i'
alex@d120432:~$
是否有可能在第二个 perl
中获得相同的输出命令?我找不到使用 i
作为重复计数的正确语法。
Is it possible to get the same output in the second perl
command? I cannot find correct syntax to use i
as repeat count.
推荐答案
您必须转义内部双引号,并在shell中使用双引号进行变量扩展:
You will have to escape inner double quotes and use double quotes in shell for variable expansion:
perl -e "print \"\x41\x42\x43\x44\x0a\" x $i"
ABCD
ABCD
以下变体也可能起作用:
Following variant may also work:
perl -e 'print "\x41\x42\x43\x44\x0a" x '$i
这篇关于perl和bash变量替换,带有十六进制字符和重复计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文