1 shell脚本的运行机制
解释运行,无需编译链接.
2 第一个shell脚本
hello.sh
#!/bin/sh
echo "hello.world"
#为注释符,第一句表示shell程序被/bin目录下的sh解释器执行.
第二句 echo 相当于printf .
3 Linux下执行shell脚本的三种方法
- ./hello.sh
- source hello.sh
- bash hello.sh (bash是脚本解释器)
输出结果是
hello.world
4 shell中的变量定义和引用
- shell是弱类型语言,直接定义并赋值(用=号)即可,不需加类型,并且赋值时不能有空格.
- 变量定义后可以再次赋值,覆盖前面的值
- 变量引用要$号, $var 或者 ${var}
5 shell中无引号,单引号和双引号区别
- 无引号和单引号,双引号均可以用来输出字符串
- 但是无引号和单引号不能输出转义字符和 “
6 shell中调用linux命令
使用 反引号``括起来或者直接执行