加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Shell编程

发布时间:2020-12-15 19:19:42 所属栏目:安全 来源:网络整理
导读: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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读