-3

I'm trying to transform a bash script to python, and I have a piece of code that I want to understands better. The script:

dd < "$file" skip=$start count=$((end - start)) iflag=skip_bytes 2> /dev/null |
        (
            if [ -n "$dir" ]; then
                mkdir -p -- "$dir/$subdir"
                cd -- "$dir/$subdir"
            fi
            cpio -i "$@"
        )

My understanding is that I read from a file I junk over "$start" bytes and go further count bytes. So I presume I can do this with seek.

How do I translate iflag=skip_bytes to python ?

2
  • "How do I translate iflag=skip_bytes to python ?" You already did if you interpret skip as bytes. It would be blocks otherwise. Commented Jul 28, 2021 at 12:09
  • You might want to add the appropriate help/man information for your platform. There is no iflag parameter for BSD dd, for example. Commented Jul 28, 2021 at 12:12

1 Answer 1

1

From https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation

‘skip=n’

Skip n ‘ibs’-byte blocks in the input file before copying. If ‘iflag=skip_bytes’ is specified, n is interpreted as a byte count rather than a block count.

So, if you didn't have iflag=skip_bytes in your bash script, you'd have to multiply $start by the block size before seeking. But since the iflag=skip_bytes is there, no multiplication is necessary and you only need to seek by $start bytes.

1
  • Same goes for count which normally counts in blocks, but uses bytes if iflag=skip_bytes is there.
    – Socowi
    Commented Jul 28, 2021 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.