the shell conditional file, determining the value, determined character; logical comparison, the test of

Analyzing the shell conditions: (Option Reference man test)

1. File judgment:
  judgment directory exists and does not exist: test after -d / home see the results performed using $ 0 representing a directory; test command to perform regardless of the outcome, are not being given, returns only 0 or 0?
  The Test -d / home syntax is equivalent to [-d / home] test can be used [instead, the latter] is just an argument, do not take this as the square brackets look, people are command ah.


2. Analyzing values:
  IF [-ne the UID $ 0]; the then the UID $ user determines whether the current user is root, whether a non-zero 0; -ne i.e., meaning not equal to


3. character judgment:
  IF [the USER $ = "root"]; the USER the then $ to get the user name currently logged in, directly determine the character and use == = = to the same effect.

 

Logical comparison: [] used for multi logical comparison, as follows: 

   [-Z "$ name"] [ -n "$ name"] is used to determine whether the length of the variable 0, note that the shell character variables are best when used with double quotes
  when the shell, the variable is null or unset length is 0

Guess you like

Origin www.cnblogs.com/quzq/p/12168501.html