Please ask the following shell script flow:
1. Why use $ * instead of $1 in a function?
2. how does while true jump out of the function?
3. The first two returns of case return the function return value?
4. Please explain the process of execution and do not understand it. . .
10 yes_or_no(){
11 echo "Is your name $*"
12 while true
13 do
14 echo "Enter yes or no"
15 read x
16 case $x in
17 y | yes) return 0; ;
18 n | no ) return 1; ;
19 * ) echo "Enter yes or no"
20 esac
21 done
22 }
23
24 echo "Original parameters are $*"
25 if yes_or_no "$1"
26 then
27 echo "Hi $1, nice name"
28 else
29 echo "Never mind"
30 fi
31 exit 0
1. What is inside the function is the parameter passed to the function, that is, the pile of things that follow when the function is called. For this script, what is inside the function
$*
That’s 25 lines.$1
2. Only inputyes/no
It will only return when it is time to jump out of the function.
3. It is the state value after the function is executed, 0 means correct, and non-zero means error.