linuxshelldd

Convert varible to number for dd command using Shell script


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?


Solution

  • 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