1 / 10

Shell基础(二 )

Shell基础(二 ). Powered by @li3huo. 回顾. 本系列的第一次:思路 为什么要自动化 哪些地方可以自动化 自动化的思路 第二次:基础(一) 参考资料介绍 什么是好脚本 变量: Scope of Variables 通配符: Wildcards 转义符: Escape Characters 循环: Loops. 内容提要. 条件验证工具: test, [ -- condition evaluation utility 选择结构: case 变量(二)(三) 预置变量: Pre -set Variables

renata
Download Presentation

Shell基础(二 )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Shell基础(二) Powered by @li3huo

  2. 回顾 • 本系列的第一次:思路 • 为什么要自动化 • 哪些地方可以自动化 • 自动化的思路 • 第二次:基础(一) • 参考资料介绍 • 什么是好脚本 • 变量:Scope of Variables • 通配符:Wildcards • 转义符:Escape Characters • 循环:Loops

  3. 内容提要 • 条件验证工具:test, [ -- condition evaluation utility • 选择结构:case • 变量(二)(三) • 预置变量:Pre-set Variables • 默认值:DefaultValues • 外部程序调用:External Programs

  4. 条件验证工具 • [ 是一个命令 • 引入一个选择结构:if • 练习一 • 特殊符号的用法:; \ • 对数字、字符和文件进行判断 • 练习二

  5. 选择结构 • 控制结构回顾 • 循环结构 • 选择结构:if、case • Case • 练习:talk.sh

  6. 示例 #!/bin/sh if使用格式 if [ something ]; then echo "Something” elif[ something_else ]; then echo "Something else" else echo "None of the above" fi 说明 如果if 和then在一行,要用分号 其他选择用elif 最后结束要fi

  7. 示例 #!/bin/sh USER=`whoami` case $USER in root)echo "You can do all the operations" ;; liyan)echo "You can do some operations" ;; *)echo "Sorry,you can not do anything" ;; esac case使用格式 case var in value1) cmd1 ;;value2)cmd2 ;; ......... *) cmdn ;; esac 说明 ) exit/break *)

  8. 变量 • 预置变量 • 有些变量是预置的,我们不能给它赋值 • 传入参数:$0 .. $9 / $# / $@ • 命令返回值: $? • 进程Id:$$ / $! • 内部分隔符:IFS • 练习 • 默认值 • 使用test中的-z参数 • :-和:=的用法 • 练习 • name.sh • name2.sh

  9. 外部程序调用 • 使用反引号 • 外部命令 • grep • cut • 练习 • checkType.sh

  10. 让我们跑得更快一点儿! NQSDK测试机地址: 192.168.0.35 /opt/shell

More Related