Alternatives to goto in bash

As we know:

  1. There is no goto statement support in bash.

  2. goto is useful for certain situations, especially for debugging.

So, is there any alternative mechanisms to goto in bash?

Robert Copeland gave an interesting hacking to this problem: http://bobcopeland.com/blog/2012/10/goto-in-bash/

The idea is like the self-modifying code. But the difference is to generate a piece of the script and eval (run) it. This is not exactly the goto statement, but achieve the very close results.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *