UniqueDelimitersShellPattern

Last edit October 3, 2003
When combining several input streams into a single file, so each part can be separated later, you want to separate the parts with a unique delimiter:
 cat <<'THISISADELIMITER'
 . . . .
 . . . .  stuff
 . . . .
 THISISADELIMITER
However, there is no guarantee that the delimiter you choose isn't already a line in the file. You could embed ends-of-file in the file, but reading past ends-of-file often causes strange behavior.

Therefore:

Prepend every line of the archive file with any character different from the first character of the delimiter; that is sufficient to make aliasing impossible:
 #!/bin/sh
 PATH=/bin:/usr/bin
 echo '# To unbundle, sh this file'
 for i
 do
	echo "echo $i 1>&2"
	echo "sed 's/.//' >$i <<'//GO.SYSIN DD $i'"
	sed 's/^/-/' $i
	echo "//GO.SYSIN DD $i"
 done
As a result, there is no aliasing; the archive file can have explicit delimiters that make it more self-documenting and easy to persue with an editor.

Many thanks to BrianKernighan, who is author of the bundle script.
CategoryUnixShellPattern