The assignment statement in bash (like in any other programming language) requires a single equal signs. You used two of them, so that the second one has been included in the value of the variable n:
when the shell performs the variable substitution in line 4, the test statement results in
Code:
while [[ =0 -le 23 ]]
which is obviously wrong.
Regarding your original question, the problem is
how to pass a shell variable to an awk program. Your code will not work as expected because you treat $n as a shell variable inside the awk code, whereas in awk $n will be interpreted as the n-th field. Furthermore take in mind that shell variables are not expanded inside single quotes. For an explanation of the correct way to pass a shell variable, please see
http://www.gnu.org/s/gawk/manual/gaw...hell-Variables.
Basically you can use the -v option and assign the value $n to the awk variable n. However in this case the "n" inside the regular expression will be treated literally. In other words, you cannot use awk variables inside a regexp. What you need is a
dynamic regexp, e.g.
Code:
awk -v n=$n -F, '{ if (($3 ~ /^965/) && ($26 ~ /^bulksms/) && ($14 ~ "2011/12/07 " n ":[0-1][0-9]:[0-9][0-9]")) print $17}' file
The alternative is to correctly use a sequence of single and double quotes to write down the command:
Code:
awk -F, '{ if (($3 ~ /^965/) && ($26 ~ /^bulksms/) && ($14 ~ /2011\/12\/07 '"$n"':[0-1][0-9]:[0-9][0-9]/)) print $17}' file
Here you close the initial single quote when you want to let bash do the variable substitution and re-open single quotes to write down the rest of the awk code. Hope this helps.