I have a file named SOURCE, and I want to create a file named TARGET of a specific length, containing copies of SOURCE. TARGET's length is not necessarily an integer multiple of SOURCE's length. I want to do this using bash on Linux.
My first try was this:
while true; do cat SOURCE; done | head -c $TARGET_LENGTH > TARGET
That hangs after writing the specified number of bytes to TARGET. How do I make it not hang? (I suspect I'm missing a detail around how pipes and signals work.)
Edit: I know that while true runs forever, but I expected the head command to shut everything down after consuming the specified number of bytes.
How about this?
while cat SOURCE; do true; done | head -c "$TARGET_LENGTH" > TARGET
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With