Reference "Bird's private cuisine--linux Basic Study (third edition)".
In "bird Brother's private cuisine--linux Basic Study (third edition)" in the 11th chapter, bird Brother about the variables of the test and the content of the replacement, the bird brother finally illustrated in the example of variable substitution '-', ' = ', '? ' Usage of three special symbols.
After reading these routines, give me the biggest feeling is Var=${str-newvar} or Var=${str=newvar} or Var=${str? Newvar} variable substitution is the only three-mesh operator in C language? is similar in usage:
max= (x>y)? (x:y). Here we analyze the following:
Var=${str-newvar}: If Str does not exist, then Var=newvar; Select the latter
If STR exists, then VAR=${STR}; Select the former
Similarly, "=" can also be interpreted as:
Var=${str=newvar}: If Str does not exist, then Var=newvar; Select the latter but because it is equal to the number, so str=newvar;
If STR exists, then VAR=${STR}; Select the former str to keep the original content
For "? "is interpreted as"
Var=${str? No this variable}: If Str does not exist, the output error message: no this variable; Select the latter
If STR exists, then VAR=${STR}; Select the former str to keep the original content
Testing and content substitution for shell variables