M
M
Maxim2019-09-26 12:45:54
bash
Maxim, 2019-09-26 12:45:54

How to correctly translate the description of a case statement in bash?

Hello.
I am translating an article, but I cannot translate it correctly and clearly.
Part of the article (I highlighted in bold that I can’t translate so that the sentence looks normal):
The last of the important iteration loops is case. The case statement is used to
evaluate a number of expected values. The case statement in particular is important
in Linux startup scripts that on previous versions of RHEL were used to start
services. In a case statement, you define every specific argument that you expect, which
is followed by the command that needs to be executed if that argument was used.
In Listing 31.10 , you can see the blueprint of the case statement that was used on
RHEL 6 to start almost any service.
Here is the actual listing:

case "$1" in
     start)
          start;;
     stop)
          rm -f $lockfile
          stop;;
     restart)
          restart;;
     reload)
          reload;;
     status)
          status
          ;;
     *)
          echo "Usage: $0 (start|stop|restart|reload|status)"
          ;;
esac

Next came the paragraph. I can't translate it correctly either.
The case statement has a few particularities. To start, the generic syntax is case
item-to-evaluate in . Then follows a list of all possible values ​​that need to be
evaluated. Each item is closed with a ). Then follows a list of commands that need to be
executed if the specific argument was used. The list of commands is closed with a
double semicolon. This ;; can be used directly after the last command, and it can be
used on a separate line. Also notice that the *) refers to all other options not
previously specified. It is a “catchall” statement. The case iteration loop is closed by an
esac statement.
Notice that the evaluations in case are performed in order. When the first match
is made, the case statement will not evaluate anything else. Within the evaluation,
wildcard-like patterns can be used. This shows in the *) evaluation, which matches
everything. But you could as well use evaluations like start|Start|START) to match
the use of a different case.
Help. I do it for the site so that it would be useful for others.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question