Shell script basics-bash variables and logic run

Terminal, the interface program attached to the terminal:
GUI: KDE, GNome, Xfce
CLI: / etc / shells
bash features :
command line expansion: ~, {}
command alias: alisa, unalisa
command history: history
file name wildcard: glob
Shortcut key: Ctrl + a, e, u, k, l
command completion: $ PATH
path completion:
bash feature command hash
cache previous search results: key-value key: search key value: value
hash command
hash: column a
hash -d command: command to delete the cache
hash -r: empty
bash of features: variable
program: instruction data +
instruction: providing a program file
data: the IO devices, files, pipes, variable
program: algorithms + data structures
variable Name + pointed to the memory space
variable assignment: name = value
Variable type: storage format, data range, participating operation
programming language:
strong type variable
weak type variable:

  1. bash treats all variables as characters
  2. Variables in bash do not need to be declared in advance.
    Variable replacement: replace the position where the variable name appears with the data
    variable reference in the memory space pointed to : $ (var_name), $ var_name Generally, parentheses can omit the
    variable name: the variable name can only contain numbers, Letters and underscores, and can not start with numbers, can not use the reserved characters of the program, such as: if, else, then, while
    Shell script basics-bash variables and logic run

Bash variable type:

Local variables : The scope is only the current shell process

  1. Variable assignment: name = value
  2. Variable reference: $ {name}, $ name can omit the curly braces in most cases
  3. View variable set
  4. Undo variable: unset name is not a variable reference here, so don't use $

Environment variables:
Variable assignment:

  1. export name=value
  2. name=value
    export name
  3. declare -x name= value
  4. name=value
    declare -x name
    Shell script basics-bash variables and logic run

Shell script basics-bash variables and logic run
Variable assignment:
local variable: scope is only a certain code snippet (function context)
positional parameter variable: the parameter passed when the shell process executing the script
special variable: a variable with special functions built into the shell

  1. $?
    1. 1 0: Success
    2. 21-255: Failure
      Note: bash built a number of environmental variables (usually all uppercase) used to define the bash of the working environment
      PATH, HISTFILE, HISTSIZE, HISTFILESIZE, HISTCONTROL, SHELL, HOME, UID, PWD, OLDPWD
      viewing environment variable : Export, declare -x, printenv, env
      undo environment variable: unset name
      read-only variable:
      1. declare -r name
      2. The readonly name
        read-only variable cannot be reassigned and does not support undo: the storage time is the life cycle of the current shell process, which terminates as the shell process terminates
        Shell script basics-bash variables and logic run

Bash features many command execution:
~] # COMMAND1; COMMAND2; COMMAND3; ............
Logical operation:
operand: true (true, yes, on, 1) false (false, no, off, 0)

  1. 与:
    1&&1=1
    1&&0=0
    0&&1=0
    0&&0=0
  2. Or:
    1 || 1 = 1
    1 || 0 = 1
    0 || 1 = 1
    0 || 0 = 0

  3. Not
    :! 1 = 0
    ! 0 = 1
    Short circuit rule:

~] # COMMAND1 && COMMAND2
COMMAND1 is "false", then COMMAND2 will not run
If COMMAND1 is "true", then COMMAND2 must run
Shell script basics-bash variables and logic run

Guess you like

Origin blog.51cto.com/11195311/2489170