Shell - 简明Shell入门
本文以示例和注释的方式,对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 - 文本处理 :http://www.cnblogs.com/anliven/p/7436766.html
- Shell - Vim :http://www.cnblogs.com/anliven/p/7414061.html
- Shell - Tips :http://www.cnblogs.com/anliven/p/7492379.html
Shell - 简明Shell入门的更多相关文章
- Shell - 简明Shell入门01 - 第一个脚本(HelloShell)
示例脚本及注释 #!/bin/bash echo "hello shell!" # 打印字符串"hello shell!" echo "Date: & ...
- Shell - 简明Shell编程
本文是对Shell脚本编程的总结和回顾,所有涉及的脚本均已做了基本的调试和验证. [toc] 测试环境信息 [root@CentOS7 ~]# uname -a Linux CentOS7 3.10. ...
- Shell - 简明Shell入门15 - 调试(Debug)
示例脚本及注释 #!/bin/bash -x for filename in t1 t2 t3 do touch $filename.txt echo "Create new file: $ ...
- Shell - 简明Shell入门14 - 操作符(Operator)
示例脚本及注释 #!/bin/bash echo "No code, just some comments." # ### 通配符 # * 代表任意(0个或多个)字符 # ? 代表 ...
- Shell - 简明Shell入门13 - 用户输入(UserInput)
示例脚本及注释 1 - arguments #!/bin/bash if [ -n "$1" ];then # 验证参数是否传入 echo "The first para ...
- Shell - 简明Shell入门12 - 定制输出(ColorOutput)
示例脚本及注释 #!/bin/bash echo -e "\033[32m" # 设置输出属性,绿色字体 echo "This is a test!" echo ...
- Shell - 简明Shell入门11 - 调用脚本(CallTheScript)
示例脚本及注释 主脚本: CallTheScript.sh #!/bin/bash . ./11-subscript.sh # 调用其他脚本;注意点号"."和文件路径之间有一空格; ...
- Shell - 简明Shell入门09 - 重定向(Redirection)
示例脚本及注释 #!/bin/bash pwd > 1.log # 输出重定向到指定文件 date 1> 1.log # ">"与"1>" ...
- Shell - 简明Shell入门08 - 函数(Function)
示例脚本及注释 #!/bin/bash function Check() # 使用function定义函数 { Say # 通过函数名直接调用函数 if test $1 then return 0 # ...
随机推荐
- 在IDEA中停止和关闭SonarLint自动检查,手动运行SonarLint检查代码
关闭SonarLint自动检查代码 有时敲一行代码SonarLint插件就会自动检查,让人感觉很不舒服,还会使电脑卡顿: 依次点击:File -> Settings 或直接Ctrl+Alt+S ...
- FlannBasedMatcher 立体匹配
#include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #i ...
- Python学习笔记-常用内置函数
输出:print() 功能:输出打印 语法:print(*objects, sep=' ', end='\n', file=sys.stdout) 参数:objects----复数,表示可以一次输出多 ...
- 获取CNVD的cookie
def getCookie(self): #获取cookie spiderFirefox = webdriver.Firefox() spiderFirefox.get("http://ww ...
- 二、putty的下载安装和基本使用方法教程
转载自:https://baijiahao.baidu.com/s?id=1597811787635071952&wfr=spider&for=pc PuTTY是一款开源(Open S ...
- 每月最后一周的周六晚上21:00执行任务-crontab
0 21 * * 6 /bin/sh /root/time.sh #“6”代表周六 时间判断脚本如下: #!/bin/bash if [ "$(date -d "+7 days&q ...
- python3+scrapy 趣头条爬虫实例
项目简介 爬取趣头条新闻(http://home.qutoutiao.net/pages/home.html),具体内容: 1.列表页(json):标题,简介.封面图.来源.发布时间 2.详情页(ht ...
- 查看class实际执行的类路径
查看class真实归属的jar包位置getClass().getClassLoader().getResource(getClass().getName().replace('.', '/') + & ...
- Oracle中为表设置自动增长的标识列
-- Create sequence create sequence INNERID minvalue 1 maxvalue 99999999999999 start with 1 increment ...
- CentOS6.9安装Python-3.6.3
CentOS6.9上默认安装的python版本是2.6的.因为系统自带的python会被系统很多软件环境依赖使用,所以不要卸载原来的Python版本,根据需要进行安装新版本即可,本人此处安装的是3.6 ...