• Linux 学习 之 bash


    Anything is programmable with defined syntax and common lib.

    Bash Shell is created to programme to Linux command in defined grammar

    • Linux 中的bash shell 拥有自己的一些语法,通过语法我们可以对命令进行编程,也就是脚本编写。脚本就是用一些特定的语法把要执行的命令联合起来自动执行。参考:http://wenku.baidu.com/view/e034565bbe23482fb4da4ce8.html  &  http://www.cnblogs.com/zemliu/archive/2012/05/13/2497784.html
    • What is a shell?

      At its base, a shell is simply a macro processor that executes commands. The term macro processor means functionality where text and symbols are expanded to create larger expressions.

      A Unix shell is both a command interpreter and a programming language. As a command interpreter, the shell provides the user interface to the rich set of GNU utilities. The programming language features allow these utilities to be combined. Files containing commands can be created, and become commands themselves. These new commands have the same status as system commands in directories such as/bin, allowing users or groups to establish custom environments to automate their common tasks.

      Shells may be used interactively or non-interactively. In interactive mode, they accept input typed from the keyboard. When executing non-interactively, shells execute commands read from a file.

      A shell allows execution of GNU commands, both synchronously and asynchronously. The shell waits for synchronous commands to complete before accepting more input; asynchronous commands continue to execute in parallel with the shell while it reads and executes additional commands. The redirection constructs permit fine-grained control of the input and output of those commands. Moreover, the shell allows control over the contents of commands’ environments.

      Shells also provide a small set of built-in commands (builtins) implementing functionality impossible or inconvenient to obtain via separate utilities. For example, cd, break, continue, and exec) cannot be implemented outside of the shell because they directly manipulate the shell itself. The history, getopts, kill, or pwd builtins, among others, could be implemented in separate utilities, but they are more convenient to use as builtin commands. All of the shell builtins are described in subsequent sections.

      While executing commands is essential, most of the power (and complexity) of shells is due to their embedded programming languages. Like any high-level language, the shell provides variables, flow control constructs, quoting, and functions.

      Shells offer features geared specifically for interactive use rather than to augment the programming language. These interactive features include job control, command line editing, command history and aliases. Each of these features is described in this manual.

    • bash shell reference: http://www.gnu.org/software/bash/manual/bash.html
    • bash shell 都有什么命令呢

    • how use these bash shell command? type help command-name

    • 赋值语句: var=value;变量解析: ${var}; 命令解析: $(command) = `command`;双引号" " : 变量内容,并做转义;单引号' ' : 变量内容,但不做转义;反单引号` ` : 同 $()

    • we can get all environment variable by command `env`

    •  if shell command

    • Bash Conditional Expressions: The fromat is  [ -option file ], Note the space after [ and before ]
      1. [ -a file ]    True if file exists.
      2. -b file    True if file exists and is a block special file.
      3. -c file    True if file exists and is a character special file.
      4. -d file    True if file exists and is a directory.
      5. -e file    True if file exists.
      6. -f file    True if file exists and is a regular file.
      7. -g file    True if file exists and its set-group-id bit is set.
      8. -h file    True if file exists and is a symbolic link.
      9. -k file    True if file exists and its "sticky" bit is set.
      10. -p file    True if file exists and is a named pipe (FIFO).
      11. -r file    True if file exists and is readable.
      12. -s file    True if file exists and has a size greater than zero.
      13. -t fd      True if file descriptor fd is open and refers to a terminal.
      14. -u file    True if file exists and its set-user-id bit is set.
      15. -w file    True if file exists and is writable.
      16. -x file    True if file exists and is executable.
      17. -G file    True if file exists and is owned by the effective group id.
      18. -L file    True if file exists and is a symbolic link.
      19. -N file    True if file exists and has been modified since it was last read.
      20. -O file    True if file exists and is owned by the effective user id.
      21. -S file    True if file exists and is a socket.
      22. file1 -ef file2    True if file1 and file2 refer to the same device and inode numbers.
      23. file1 -nt file2    True if file1 is newer (according to modification date) than file2, or if file1 exists and file2 does not.
      24. file1 -ot file2    True if file1 is older than file2, or if file2 exists and file1 does not.
      25. -o optname         True if the shell option optname is enabled. The list of options appears in the description of the -o option to the set builtin (see The Set Builtin).
      26. -v varname         True if the shell variable varname is set (has been assigned a value).
      27. -z string    True if the length of string is zero.
      28. -n string
      29. string    True if the length of string is non-zero.
      30. string1 == string2
      31. string1 = string2    True if the strings are equal. ‘=’ should be used with the test command for POSIX conformance.
      32. string1 != string2   True if the strings are not equal.
      33. string1 < string2    True if string1 sorts before string2 lexicographically.
      34. string1 > string2    True if string1 sorts after string2 lexicographically.
      35. arg1 OP arg2
      36. OP is one of ‘-eq’, ‘-ne’, ‘-lt’, ‘-le’, ‘-gt’, or ‘-ge’. These arithmetic binary operators return true if arg1 is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to arg2, respectively. Arg1 and arg2 may be positive or negative integers.

     

  • 相关阅读:
    桥接模式(从多个角度对实现进行分类)
    单例模式
    组合模式(解决 树形 ,局部与整体关系)
    备忘录模式
    适配器模式
    状态模式
    StartUML建模及生成java实体代码
    JPA删除接口报错 : org.hibernate.LazyInitializationException: failed to lazily initialize a collection, could not initialize proxy
    idea创建的gradle项目没有src目录怎么办?
    idea spring源码 gradle编译失败问题
  • 原文地址:https://www.cnblogs.com/iiiDragon/p/3230306.html
Copyright © 2020-2023  润新知