Online Resources: http://tldp.org/LDP/abs/html/...
set -e
Exit the script if an error happens
圆括号
括号中的命令将会新开一个子shell顺序执行:
(bar="hello world")
echo $bar # 无输出
&&
&& lets you do something based on whether the previous command completed successfully
$ true && echo "Things went well"
Things went well
$ false && echo "This will always run"
Internal Variables
Internal Commands
a.sh
#!/bin/sh
echo "$foo"
echo "$bar"
b.sh
foo="hello world"
bar="hello"
export foo
./a.sh
等价于==>
bar="hello"
foo="hello world" ./a.sh
2. source 或 点操作符"."
imports code into the script
# import utils
. scripts/utils.sh
source scripts/utils.sh
External Commands
In general, an external command in a script forks off a subprocess, whereas a Bash builtin does not. For this reason, builtins execute more quickly than their external command equivalents.
Basic commands: ls, cat, rm, ...