cd html || { "no html directory found" } out=../src/acit/html.py exec >"$out" # write all STDOUT to the file cat <"$out" done earlier all the output of the echo and sed statements get redirected directly into the output file # the sed acts as `cat` with a find-replace echo "$htmlname"'="""' # open multiline string sed 's/"""/\\"\\"\\"/g' "$file" # add the HTML itself, also replace all occurences of """ with escaped ones to prevent closing the string early echo '"""' # close multiline string echo "Included '$file' as html.$htmlname" >&2 done | sed '//r .header.html' #sed 's/^.*INSERT PAGE HEADER.*$/'"$header"'/' # this sed also inserts headers