I understand that fallthrough is very convenient, but given your example snippet I don't see how
case "${last_action}" in
beginning)
function1
function2
function3
;;
middle)
function2
function3
;;
end)
function3
;;
esac
would add much overhead to your code. It's still prettier than lots of if
s.
However, if your switch is more complex and you want this to be more dynamic, you can do something along the lines of:
#!/bin/bash
function1() { echo 1; }
function2() { echo 2; }
function3() { echo 3; }
last_action=$1
actions_beginning="function1 function2 function3"
actions_middle="function2 function3"
actions_end="function3"
_actions="actions_${last_action}"
for action in ${!_actions}; do
"${action}"
done
$ ./test.sh beginning
1
2
3
$ ./test.sh middle
2
3
$ ./test.sh end
3
EDIT: Just looked at your code on github and I myself would definitely go this route.