Skip to main content
1 of 3
Petr Skocik
  • 29.6k
  • 18
  • 90
  • 154

If the top and bottom are fixed, it can be something like:

cat top.txt /dev/stdin bottom.txt > text.txt 
# with cat, - works the same as /dev/stdin

followed by your compilation commands

cat top.txt /dev/stdin bottom.txt > text.txt
gcc whatever 

The first line should be a shebang line specifying your interpreter, unless you're OK with /bin/sh

 #!/bin/bash
 cat top.txt /dev/stdin bottom.txt > text.txt
 gcc whatever

If you then mark the script executable with chmod +x the_script, ./the_script will be equivalent to /bin/bash ./the_script.

If you want the scrip to abort a command fails, start it with set -e (or make the shebang line (#!/bin/bash -e).

Petr Skocik
  • 29.6k
  • 18
  • 90
  • 154