Bash Commands and Shell Scripts

发布时间 2023-05-05 20:38:26作者: 四季夏目天下第一

为了考试准备一下吧
这门课对这个领域的知识教的太浅,考的却很难,必须要额外自学一点东西

Variables in Shell Scripts

首先是 Shell Scripts 中的变量概念: Shell Scripts 中的 变量只有一种类型 string

Define variable in shell scripts

对于一个变量赋值语句 a=xxxxxx 必须是字符串 string

  • xxx单引号括起来的

    a='hello': 单引号中的内容不支持 variable substitution

  • xxx双引号括起来的

    a="$b": 双引号中的内容支持 variable substitution

  • xxx反引号括起来的

    反引号 ` `$() 符号的作用已知
    反引号中的内容是 bash command: 注意,所有 bash command 的 output 都是 string

Access variable in shell scripts

使用符号 $ 来访问变量

$a 可以视为将变量 a 中的字符串展开,即 variable substitution


Commmand sed