Run a series of tasks, but depending on progress start on task x in bash (continue switch case) -


i have series of tasks run 1 after other, depending on progress, saved in variable has start @ appropriate step.

for instance, have 5 tasks. task 1 supposed start, followed task 2, task 3 , on. if variable progress contains value 2, should start @ task 2, continue task 3 , on.

i thought achievable switch case, like:

case $progress in     1)         echo "task1"         $progress=2;;     2)         echo "task2"         $progress=3;;     3)         echo "task3";;     *)         echo "null";; esac 

the problem here switch case ends, after first match. how have switch case continue after first match?

to complement boolean.is.null's own helpful answer, here's overview of case-branch terminators:

  • ;; [the option bash 3.x]

    • exit case statement right away (from matching branch).
  • ;& [bash 4.0+]

    • unconditionally fall through next branch - in c switch statement's case handler without break. note unconditional means next branch entered, no matter condition is.
  • ;;& [bash 4.0+]

    • continue evaluating branch conditions until one, if (including *)), matches.

;; example; outputs line one:

case 1 in   1)  # entered, because matches , first condition     echo 'one'     ;;  # exits `case` statement here   ?)  # never entered     echo 'any single char.'     ;; esac 

;& example (bash 4.0+); outputs lines one , two:

case 1 in   1)  # entered, because matches , first condition     echo 'one'     ;&  # fall through next branch   2) # entered, because previous branch matched , fell through     echo 'two'     ;;  # exits `case` statement here esac 

;;& example (bash 4.0+); outputs line one , any:

case 1 in   1) # entered, because matches , first condition     echo 'one'     ;;&  # continue evaluation branch conditions   2) # not entered, because condition doesn't match     echo 'two'     ;;   *)  # entered, because it's next *matching* condition     echo 'any'     ;; # using terminator optional in * branch esac 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -