英文:
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_MEMORY
、END_ADDR
和START_ADDR
在当前shell环境中是可访问和存在的,您可以验证这一点,执行以下命令:
echo $SOME_MEMORY
、echo $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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论