Shell编程

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

http://tldp.org/LDP/abs/html/...
$PATH,${PATH}: Path to binaries
$PWD,${PWD}: Working directory (directory you are in at the time)

Internal Commands

1. export:
http://blog.51cto.com/beyond3...
export command is used to export a variable or function to the environment of all the child processes running in the current shell.

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,...

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...