跳到主要内容

Shell编程

保留字

ifthenelifelsefitime
forinuntilwhiledodone
caseesaccoprocselectfunction
{}[[]]!

变量

运算符

数据结构

数组、关联数组

控制流

  • 条件
    • if
      • -e True if file exists (regardless of type)
      • -d True if file exists and is a directory
      • -f True if file exists and is a regular file
      • -n True if the length of string is nonzero
      • -z True if the length of string is zero
    • case
    • select
    • ((…))
    • [[…]]
  • 循环
    • until until test-commands; do consequent-commands; done
    • while while test-commands; do consequent-commands; done
    • for
      • for name [ [in [words …] ] ; ] do commands; done
      • for (( expr1 ; expr2 ; expr3 )) ; do commands ; done
  • 分组
    • ()
    • {}
  • 协同

函数

fname () compound-command [ redirections ]function fname [()] compound-command [ redirections ]

  • 位置参数 ${N}
  • 特殊参数
    • *
    • @
    • #
    • ?
    • -
    • $
    • !
    • 0

Shell Expansions

  • brace expansion
  • tilde expansion
  • parameter and variable expansion
  • command substitution
  • arithmetic expansion
  • word splitting
  • filename expansion

重定向

内置命令

作业控制

参考