2.2.6.1, Case statements
(1) The case statement in the shell acts in the same way as the switch case statement in the C language, with a different format
(2) The case statement in the shell is inherently free of break and does not require a break, unlike the switch case in the C language. The case in the shell defaults to which of the matches on which one executes, and does not say that the other case is executed after execution (as if the case language in the shell defaults to a break).
2.2.6.2, invoking the shell program's arguments
(1) The C language can be passed to the program via the ARGC and argv of the main function (refer to the "4.8.3.ARGC, argv and main function" for details)
(2) The shell program itself can also be called Shishun to him. The use of parameters within a shell program is also indicated by some specific symbols, including:
$ #表示调用该shell时传参的个数. ($ #计数时只考虑真正的参数个数)
$, $, $2 Then each parameter of the argument is represented in turn.
C language:./a.out aa bb cc argc = 4, argv[0] =./a.out, argv[1] is the first valid parameter
Shell:source a.sh aa bb cc $# = 3, $ A is the name of the parser executing the shell program, and $ $ is the value of the first valid parameter, and the value of the 2nd valid parameter is $
Note: Many of the syntax features in the shell are the same as in the C language, and many are different. So the more you learn the more easily confused (the essential reason or the use of unfamiliar, less), the solution is: take notes, make a summary, write more code often use
2.2.6.3, while loop and case language and reference combination
(1) The break keyword in the shell and the C language have the same meaning (all jumps out) but the usage is different. Because the case statement in the shell is not break by default, break in the shell is used only for loop jumps. So when a case statement is embedded in the while, the break in the box jumps out of the outer while loop, not to jump out of the case statement.
(2) The value of the $# built-in variables in the shell is not immutable, but can be changed and changed by the shift instruction. The shift instruction is a bit like the left shift operator, which shifts the arguments we gave to the shell program to the left, and the original $ $ $ #少了1个.
(ix) Shell case statements, program parameters, while