本文以示例和注释的方式,对Shell编程的基本知识点进行了总结和回顾,所有脚本均已做了基本的调试和验证。

简明Shell入门

01 - 第一个脚本

脚本的定义、执行方法以及echo命令。

02 - 变量

变量的定义、分类和读取方法。

03 - 字符串

字符串的拼接、截取、匹配和替换方法。

04 - 判断

利用if/else语句进行流程控制和test命令进行条件测试。

05 - 条件

利用case语句进行流程控制以及注意事项。

06 - 循环语句

利用for循环、while循环、until循环进行流程控制和跳出循环的方法。

07 - 数组

数组的定义、元素读取和操作方法。

08 - 函数

函数的定义、参数传递和返回值。

09 - 重定向

文件描述符的定义和重定向的操作方法。

10 - 管道

管道的基本使用方法和注意事项,以及如何结合xargs命令使用。

11 - 调用

在脚本中调用其他脚本的方法和注意事项。

12 - 定制输出

设置输出属性的方法,例如指定字体及背景等。

13 - 用户输入

分别利用脚本参数位置、shift、read和getopts实现用户输入的方法和注意事项。

14 - 操作符

总结并简述常用Shell操作符。

15 - 调试

调试Shell脚本的方法和常用调试选项。

获取示例脚本

测试环境

[root@CentOS7 ~]# uname -a
Linux CentOS7 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@CentOS7 ~]#
[root@CentOS7 ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@CentOS7 ~]#
[root@CentOS7 ~]# bash --version
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[root@CentOS7 ~]#

其他信息

Shell - 简明Shell入门的更多相关文章

  1. Shell - 简明Shell入门01 - 第一个脚本(HelloShell)

    示例脚本及注释 #!/bin/bash echo "hello shell!" # 打印字符串"hello shell!" echo "Date: & ...

  2. Shell - 简明Shell编程

    本文是对Shell脚本编程的总结和回顾,所有涉及的脚本均已做了基本的调试和验证. [toc] 测试环境信息 [root@CentOS7 ~]# uname -a Linux CentOS7 3.10. ...

  3. Shell - 简明Shell入门15 - 调试(Debug)

    示例脚本及注释 #!/bin/bash -x for filename in t1 t2 t3 do touch $filename.txt echo "Create new file: $ ...

  4. Shell - 简明Shell入门14 - 操作符(Operator)

    示例脚本及注释 #!/bin/bash echo "No code, just some comments." # ### 通配符 # * 代表任意(0个或多个)字符 # ? 代表 ...

  5. Shell - 简明Shell入门13 - 用户输入(UserInput)

    示例脚本及注释 1 - arguments #!/bin/bash if [ -n "$1" ];then # 验证参数是否传入 echo "The first para ...

  6. Shell - 简明Shell入门12 - 定制输出(ColorOutput)

    示例脚本及注释 #!/bin/bash echo -e "\033[32m" # 设置输出属性,绿色字体 echo "This is a test!" echo ...

  7. Shell - 简明Shell入门11 - 调用脚本(CallTheScript)

    示例脚本及注释 主脚本: CallTheScript.sh #!/bin/bash . ./11-subscript.sh # 调用其他脚本;注意点号"."和文件路径之间有一空格; ...

  8. Shell - 简明Shell入门09 - 重定向(Redirection)

    示例脚本及注释 #!/bin/bash pwd > 1.log # 输出重定向到指定文件 date 1> 1.log # ">"与"1>" ...

  9. Shell - 简明Shell入门08 - 函数(Function)

    示例脚本及注释 #!/bin/bash function Check() # 使用function定义函数 { Say # 通过函数名直接调用函数 if test $1 then return 0 # ...

随机推荐

  1. angular中使用ckplayer播放器

    原文地址:https://www.cnblogs.com/jying/p/9519557.html ,转载请说明出处. ckplayer官网:http://www.ckplayer.com 使用ckp ...

  2. python re模块与正则表达式

    首先要先继承re模块: import re re.findall() 方法 # 返回值为列表 \w 表示一个字符,为数字,字母,下滑线之一, \W匹配任意非数字,字母,下划线 print(re.fin ...

  3. Xshell 6安装与使用教程

    随着xshell5出现评估期已过的问题,发现好多人不知道怎么下载免费版的Xshell,在这里我将详细告诉大家如何下载和安装最新的Xshell6远程管理工具. Xshell安装 1.进入xshell英文 ...

  4. Lua中面向对象

    一.Lua中类的简单实现: (1)版本——摘自 Cocos2.0中的: --Create an class. function class(classname, super) local superT ...

  5. python 之C3算法

    C3算法只要针对的Python2.3版本之后出现的新式类MRO(method resolution order) -------继承方法查询顺序;而经典类MRO则遵循的是深度优先遍历(树形结构) (1 ...

  6. FortiGate日志中session clash

    1.出现于:FortiGate v5.0和v5.2 2.出现原因 Session clash messages appear in the logs when a new session is cre ...

  7. ant 执行java文件,java文件中含中文,显示乱码

    在build.xml文件run target下添加下面一行 <sysproperty key="file.encoding" value="UTF-8" ...

  8. python基础之Day8

    一.什么是文件 文件是操作系统为用户或应用程序提供的一个读写硬盘的虚拟单位 文件的操作核心就:读.写 即我们只需要对于进行读写操作,就是对操作系统发起请求,然后由操作系统将用户或者应用程序对文件的读写 ...

  9. Spring 框架下 (增 删 改 )基本操作

    //applicationContext.xml 配置文件 <?xml version="1.0" encoding="UTF-8"?><be ...

  10. Python(五) 字典