将Shell脚本中的变量转换为dd命令中的数字。

huangapple go评论110阅读模式
英文:

Convert varible to number for dd command using Shell script

问题

我可以帮你将这段内容翻译成中文:

我使用Shell脚本解析了/proc/PID/maps,现在我有两个变量:

START_ADDR=982fe000
END_ADDR=984fe000

我想要在Shell脚本命令中使用这些变量来执行dd,类似于以下命令:

dd if=SOME_MEMORY skip=START_ADDR count=(END_ADDR-START_ADDR) of=out.bin bs=1

请问如何将这些变量转换为dd命令中可用的形式?

英文:

I parsed /proc/PID/maps using shell script , now I have 2 variable

START_ADDR=982fe000
END_ADDR=984fe000

I want to use those variable for dd using shell script command like:

dd if=SOME_MEMORY skip=START_ADDR count=(END_ADDR-START_ADDR) of=out.bin bs=1

How can I convert those variable for dd?

答案1

得分: 2

由于您没有提到您使用哪个shell,我假设您正在使用bash
请记住,您可以根据以下方式修改您的上述命令以使其正常工作。

dd if=$SOME_MEMORY skip=$START_ADDR count=$((0x$END_ADDR - 0x$START_ADDR)) of=out.bin bs=1

您需要确保变量SOME_MEMORYEND_ADDRSTART_ADDR在当前shell环境中是可访问和存在的,您可以验证这一点,执行以下命令:
echo $SOME_MEMORYecho $START_ADDR以及类似地echo $END_ADDR

英文:

As you didn't mention which shell you are using, I am assuming you are using bash.
Keeping that in mind, you can modify your above command as shown below to make it work.

dd if=$SOME_MEMORY skip=$START_ADDR count=$((0x$END_ADDR - 0x$START_ADDR)) of=out.bin bs=1

You need to make sure the variables SOME_MEMORY, END_ADDR and START_ADDR are accessible and present in current shell environment, to verify you can do
echo $SOME_MEMORY, echo $START_ADDR and similarly echo $END_ADDR

huangapple
  • 本文由 发表于 2023年1月6日 13:10:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75027151.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定