On granting the temporary writ the court or judge shall require an undertaking on the part of the applicant to the effect that the applicant will pay to the defendant enjoined such damages, not exceeding an amount to be specified, as the defendant sustains by reason of the injunction if the court finally decides that the applicant was not entitled to the injunction.