Bash scripts as commands

Hello,
the bulk of my work is run by scripts. An example is as such:

#!/bin/bash

awk '{print first line}' Input.in > Intermediate.ter
awk '{print second line}' Input.in > Intermediate_2.ter
command Intermediate.ter Intermediate_2.ter > Output.out

It works the way I want it to, but it's not very flexible. If I want to change the input, I need to manually open the script and rewrite a different file in the appropriate place. Is there a way to word it so that it would work like this:

#!/bin/bash

awk '{print first line}' VARIABLE > Intermediate.ter
awk '{print second line}' VARIABLE > Intermediate_2.ter
command Intermediate.ter Intermediate_2.ter > Output.out

and

./Script Input.in

IE, it reads the first file after the script and uses that to substitute in VARIABLE? What about with multiple variables at the same time?

#!/bin/bash
VARIABLE=$1
awk '{print first line}' $VARIABLE > Intermediate.ter
awk '{print second line}' $VARIABLE > Intermediate_2.ter
command Intermediate.ter Intermediate_2.ter > Output.out

$1 $2 ... $9 are parameters you can access as shown, parms beyond 9 are accessed as ${42}

1 Like