I have this code. But I always get an error line 34: [24: command not found.
It should execute the code in the if statement as soon as the do while loop executet the 24 time.
#!/bin/bash
input="./user.cvs"
latexStart="\\documentclass[12pt]{article}\\usepackage{labels}\\usepackage{graphicx}\\usepackage{array}\\begin{document}\\graphicspath{{./QRcodes/}}\\newcolumntype{C}{>{\\centering\\arraybackslash} m{27mm} }"
latexEnd="\\end{document}"
latexBeginLabels="\\begin{labels}"
latexEndLabels="\\end{labels}"
counter=0
touch newLabels.txt
echo "$latexStart" >> newLabels.txt
echo "$latexBeginLabels" >> newLabels.txt
while IFS=';' read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13
do
path="./QRcodes/$f2$f3.png"
vcard="BEGIN:VCARD%0AN;CHARSET=utf-8:$f3;$f2;;$f1;%0AADR;CHARSET=utf-8;INTL;PARCEL;WORK:;;$f10;$f11;;$f12;$f13%0AEMAIL;INTERNET:$f6%0AORG:$f4%0ATEL;WORK:$f8%0ATEL;FAX;WORK:$f9%0ATITLE:$f5%0AURL;WORK:$f7%0AEND:VCARD"
encodedVCard=$(echo "$vcard" | sed -e 's/\+/\%2B/g')
url="http://api.qrserver.com/v1/create-qr-code/?size=300x300&data=$encodedVCard"
wget -O "$path" "$url"
if ["${counter:-0}" -gt 21] ;
then
counter=0
echo "$latexEndLabels" >> newLabels.txt
echo "\\newpage" >> newLabels.txt
echo "$latexBeginLabels" >> newLabels.txt
fi
echo "\\begin{tabular}{ C C } \\includegraphics[height=30mm]{name.png} & Name Man \\\\ \\end{tabular}" >> newLabels.txt
let counter=counter+1
done < "$input"
echo "$latexEndLabels" >> newLabels.txt
echo "$latexEnd" >> newLabels.txt
The error is in Line 34, if ["${counter:-0}" -gt 21] ;. I got this example from Compare integer in bash, unary operator expected
What am I doing wrong?
You need
i.e. your conditional statement is separated from the surrounding square brackets by spaces.
I’m quoting
counterto be safe, but if you’re sure it’ll never be empty then you can skip that. It’s probably better to be safe than sorry, however, and follow your original pattern.