Help with Script using Command Blocks

Hello,
I am trying to create a shell script that use command block (don�t really know if this is the correct way to say it), but while one version works fine, the other one is not working at all.
So let me show an example of this "command block" I�m using and its working ok:

cat << _EOF_
`echo "All informations regarding Brand Split log. It is in order regardless it shows no date."`
`echo`
`echo "Activations:"`
`grep "^8:Mass40s --" brand_split_file`
`grep "^9:Mass --" brand_split_file`
`grep "^10:Mass Promo --" brand_split_file`
`grep "^11:Jovem --" brand_split_file`
`grep "^12:Corporate --" brand_split_file`
`grep "^13:VIP --" brand_split_file`
_EOF_

This next one is not working:

monday=`awk -F";" '{print$1}' tmp |sort -u |tail -7 |head -1`

echo $monday
cat << _EOF_
`echo "Deletion by SC on $monday"`
`echo "Mass40s : `awk -F";" '$1=="'$monday'" && $4==44' tmp |wc -l`"`
`echo "Mass : `awk -F";" '$1=="'$monday'" && $4==4' tmp |wc -l`"`
`echo "Mass Promo : `awk -F";" '$1=="'$monday'" && $4==3' tmp |wc -l`"`
`echo "Jovem : `awk -F";" '$1=="'$monday'" && $4==42' tmp |wc -l`"`
`echo "Corporate : `awk -F";" '$1=="'$monday'" && $4==6' tmp |wc -l`"`
`echo "VIP : `awk -F";" '$1=="'$monday'" && $4==5' tmp |wc -l`"`
`echo "Prestigio : `awk -F";" '$1=="'$monday'" && $4==48' tmp |wc -l`"`
`echo "Reactivation : `awk -F";" '$1=="'$monday'" && $4==46' tmp |wc -l`"`
`echo "Postpaid : `awk -F";" '$1=="'$monday'" && $4==1' tmp |wc -l`"`
`echo "T+ Employee : `awk -F";" '$1=="'$monday'" && $4==10' tmp |wc -l`"`
`echo "Stock : `awk -F";" '$1=="'$monday'" && $4==18' tmp |wc -l`"`
`echo "Paris : `awk -F";" '$1=="'$monday'" && $4==40' tmp |wc -l`"`
`echo "Boston : `awk -F";" '$1=="'$monday'" && $4==41' tmp |wc -l`"`
`echo "Sal : `awk -F";" '$1=="'$monday'" && $4==43' tmp |wc -l`"`
`echo "TC101 : `awk -F";" '$1=="'$monday'" && $4==101' tmp |wc -l`"`
`echo "TC102 : `awk -F";" '$1=="'$monday'" && $4==102' tmp |wc -l`"`
`echo "TC106 : `awk -F";" '$1=="'$monday'" && $4==106' tmp |wc -l`"`
_EOF_

This is the error output:

./the_script: command substitution: line 1: unexpected EOF while looking for matching `"'
./the_script: command substitution: line 2: syntax error: unexpected end of file
./the_script: command substitution: line 1: unexpected EOF while looking for matching `"'
./the_script: command substitution: line 2: syntax error: unexpected end of file

If you compare the two codes you will notice that while the first code has only one command ( grep ), the second has two ( echo first, and then awk ), so I�m guessing that is the problem... which is strange because if I use the `caracters` it is supose to accecpt it like a command. I have others scripts that use this.

So if you could give me a hint on how to solve this, I would be very gratefull. I'm kind on a hurry, since I making a series of script to run automatically during my well earned vacations.... (about to go crazy with all this work!)

Thank you guys!:slight_smile:

What a mess :wink:

You try to nest backticks ` ` into another. Problem is, that the line is not completely parsed so the 1st starting backtick is ended by the second, not the 4th.

I'd just write a normal shell script. HERE-Skripts that you feed with input are usually used for ftp scripts etc. Using this method in this particular case I see no benefit.

Also this can be written much more compact supposedly with 1 awk script for example. You can echo stuff with awk's print and printf as you already do and wc can be done by awk too. grep'ing of course can be done by awk too.

Hi there zaxxon
I know it is a mess (big time!), but this is just one part of the script and I chose to use command blocks because its server me better (I think) this way, because the output format is important since it will be used for treatment later on in the script.
So if it is possible, do you know of any way to nest the backtick in a correct form so it will not end with the first one but the last one?
Meanwhile I will try to follow your suggestion by rewriting the script without the blocks.
Thank you for your fast replay!

if you use the $( .. ) syntax in place you'll then be able to nest them.

Hi there,
In place where? I tried (in different positions) already but it seems to ignore the $(...) syntax altogether and produce a similar error output:

./the_script: command substitution: line 1: unexpected EOF while looking for matching `"'
./the_script: command substitution: line 2: syntax error: unexpected end of file
./the_script: command substitution: line 1: unexpected EOF while looking for matching `"'
./the_script: command substitution: line 2: syntax error: unexpected end of file

In state of

`echo "Mass40s : `awk -F";" '$1=="'$monday'" && $4==44' tmp |wc -l`"`

try

$( echo "Mass40s : $(awk -F";" '$1=="'$monday'" && $4==44' tmp |wc -l)")

Frans,
It worked perfectly! I thought that only backtick (`) should be used in this type of command build, but $(..) syntax is good also, perfect for this situation.

So Frans and Zaxxon thank you very much for you help and time.

Take care!

The backticks become obsolete and the "$()" makes the scripts more readable.