In all actions of forcible entry and detention as well as of forcible detention only, notwithstanding the execution of an undertaking or filing of a proper cash bond for supersedeas or appeal, the judgment for restitution of the premises may be enforced, in the discretion of the court, or a judge thereof in vacation, upon the execution of a bond with sufficient surety, to defendant, or the deposit of a cash bond in such sum as the court shall fix, conditioned that in case the plaintiff shall finally be defeated he will pay the defendant his costs and all damages he may have suffered by reason of the execution of the judgment, the bond to be approved by the court or judge.