The person who wrote the script was simply trying to make it easier to see everything up top that drives the look of the output and the script's functionality. They seem to have failed :) to make it easier for you.
If you read about how awk works (google it or read man awk
), you'll see it wants a sequence of pattern {
statements ... }
. (This is an over simplification.) The names like HEADER
and HEADERIZE
are shell variables whose values are assigned at the top of the script and whose values are used later where they are preceded by "$". See that $AWK "$HEADERIZE
line? The script is going to run awk (presumably elsewhere the variable AWK is defined as something like awk
or /usr/bin/awk
or something like that). The parameters to awk will start with the value of the HEADERIZE variable as defined on the second non-blank line there. So the line will really read (assuming the AWK
variable is defined to be awk
):
awk "BEGIN {print "$HEADER"}"
and so on.
If you want to see how this all works, substitute echo
for awk
or redefine the AWK
variable to be echo
using something like
export AWK=echo
and re-run the script. You'll see the command lines as they would have been passed to awk
.
The reason there are two commands at the bottom appears to be so that the output file, whose name is the value of the variable TEE_DEST
, will contain two entries as a result of this script's execution. One is from the first command where the output of the execution of a command line from the variable CMD
will be stored in the file named $TEE_DEST
and then passed to the awk
command whose output will be displayed on the terminal. Then the second time simply uses echo
to put the string Cmd = [$CMD]
through the awk
script, appending that script's output to the file $TEE_DEST
as well.
You can find the value of each of a variable named VARIABLE
easily by using
echo $VARIABLE
This allows you to run bits of the script by pasting them into your terminal window and examine the contents. This, I have found, is an excellent way to learn scripting.
If you want to set a variable's value, you do something like what I suggested above when I told you to overwrite the value of AWK
with echo
:
export VARIABLE=new value for the variable