Bash中的特殊字符

2017-03-20  本文已影响0人  zhaoyu775885

1. '#' sharp字符

  • 几乎用于注释,除了#! 在sh文件开头用于标识解释器

echo 将所有的参数作为字符进行输出,各个参数用空白字符

echo test # test
echo test \# test
echo test "\#" test
echo test '\#' test
string=test
echo $string
echo "${string}"
echo '${string}'

2. ';' semicolon 分号字符

  1. 分隔shell命令
  2. 结束case选项,双分号

3. '.' dot 点号字符

当前shell中执行,相当与source命令

如果sh文件中有exit 0,呵呵你懂得

4. " ' " or " " " 引号字符

  • 当然是要pairing出现,用于有空格的字符串参数
  • double quotation "" 将除'$','','`'(backquote) 字符外的所有字符当作普通字符,包括转义字符,
  • single quotation '' 更绝,一切在里面的都是字符,毫无例外

5. slash and back-slash

  • '/' slash mark is as delimiter in path or arithmetic division
  • '' back-slash used for escape sequence

6. ' ` ' backquote 反引号

  • to be continued

7. ':' colon 字符

  1. 空命令,可以作占位符
  2. true, 因为返回码exit status是0
  3. 变量扩展/子串替换
  4. 特殊环境变量的delimiter,如PATH

8. '?' question mark

  • 与':'字符一起构成三元运算符

9. '$' dollar 字符

  1. 变量替换,或者说,叫变量引用?
  2. 命令替换,与backquote相同

10. parentheses ()

  1. 命令组,但是在子进程中运行,对父进程没有影响
  2. initilize array, shell 的数组是用空格来分割的

11. brace {}

  1. 与'$'一起,引用变量
  2. 文件名扩展
  3. 构成匿名函数,内部变量对文件都是可见的

12. brackets 方括号

  1. 等效于内建命令test,不等于外部工具test
  2. 引用数组中的指定元素,下标由[]中参数确定

13. angle brackets 尖括号 '>'

  • 重定向

14. vertical line '|'

  • pipe for command link

15. dash ' - '

  • before any options of any command
  • 用于重定向stdin或stdout
上一篇 下一篇

猜你喜欢

热点阅读