How would one simulate a call to execve with dd? Seems like a totally different problem domain.
How would one simulate a call to execve with dd? Seems like a totally different problem domain.
cat foo | ( dd bs=$HEADERSIZE skip=1 of=/dev/null; process-foo-contents ) tail -c +$HEADERSIZE <foo (dd bs=$SIZE1 count=1 of=file1; dd bs=$SIZE2 ... (head -1 > /dev/null; cat -) < file $ tail -n +2 file
From tail(1): -n, --lines=K
output the last K lines, instead of the last 10; or use -n +K to output lines starting with the KthIt happens to work on GNU head when stdin is seekable file, because GNU head specifically rewinds the stream before exiting:
$ (strace -e read,write,lseek head -1 > /dev/null; cat -) < file
...
read(0, "hello\nworld\n", 8192) = 12
lseek(0, -6, SEEK_CUR) = 6 # <-- here
write(1, "hello\n", 6) = 6
+++ exited with 0 +++
If not for that explicit `lseek`, `head -1` would have skipped the entire 8k buffer.As far as I know, this is exclusive to GNU cat. Neither Busybox nor OSX cat will do this, and will therefore throw away an entire buffer instead of just the first line. You can try it out:
(busybox head -1 > /dev/null; cat -) < file
Tail is the right tool for the job here. But if you wish to stick with your idiom, read will reliably consume a single line of input, regardless of how it is implemented:
(read -r; cat) < fileThis is just as inefficient as it sounds, but it doesn't matter much in practice since you rarely read a lot with it.