Skip to main content
added 283 characters in body
Source Link
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

or

{ 
  echo 123 #top.txt
  cat
  echo 456 #bottom.txt
} > text.txt 

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).

Edit:

cat expects a whole file (until you enter ctr-d -- the end of file marker). If you want just one line, you can do read -r something; printf '%s\n' "$something" or head -n1.

You can read the help pages of the commands with man $command or help $command.

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

or

{ 
  echo 123 #top.txt
  cat
  echo 456 #bottom.txt
} > text.txt 

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).

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

or

{ 
  echo 123 #top.txt
  cat
  echo 456 #bottom.txt
} > text.txt 

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).

Edit:

cat expects a whole file (until you enter ctr-d -- the end of file marker). If you want just one line, you can do read -r something; printf '%s\n' "$something" or head -n1.

You can read the help pages of the commands with man $command or help $command.

added 102 characters in body
Source Link
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

or

{ 
  echo 123 #top.txt
  cat
  echo 456 #bottom.txt
} > text.txt 

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).

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).

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

or

{ 
  echo 123 #top.txt
  cat
  echo 456 #bottom.txt
} > text.txt 

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).

Source Link
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).