Trying to figure out how to have a shell script only take fix-length blocks out of
stdin. I would have thought something like this would have worked, but it does not:
#!/bin/bash value=0 while [ "$value" != "-1" ]; do read -r -d '' -n 20 value if [ "$value" != "-1" ]; then dd conv=notrunc status=none of=/path/bigfile.bin bs=1M count=1 seek=$value fi done
In a nutshell I am trying to copy specific blocks from a large file to the same file a remote location. The data sent from the sending script has a block location (20 bytes) followed by a 1 MiB of the data to be written to that location. It is finished when the location is -1.
I have a setup that works fine if running a compiled C program, but I'd like to avoid this and run with the native shell commands. The problem is, it doesn't seem that
dd consumes any data, and all of it is handled by the
stdin be consumed by multiple commands?