一、简介

shell是用户和操作系统交互的命令行解释器。

shell有很多种:

  bash、csh、sh、ksh、、、

我们等了linux时看到的命令行就是一个bash。

二、第一个脚本:

[root@linux1 script]# vim first.sh
#!/bin/bash
#auther:xiaofan
#time:2016.10.4
#井号是注释
echo "hello word"

执行脚本:

方法1:

[root@linux1 script]# bash first.sh
hello word

[root@linux1 script]# sh first.sh
hello word

方法2:
[root@linux1 script]# chmod +x first.sh
[root@linux1 script]# ./first.sh
hello word

查看脚本执行的过程:

[root@linux1 script]# sh -x first.sh
+ echo 'hello word'
hello word

三、变量

变量分为两大类:

  局部变量:需要自己定义。

  环境变量:系统自带的。

变量定义:

  变量名称=变量值

调用自定义变量:

[root@linux1 script]# name="xiaofan"
[root@linux1 script]# echo "my name is $name"
my name is xiaofan
[root@linux1 script]# echo my name is $name
my name is xiaofan
[root@linux1 script]# echo 'my name is $name'   #注意单引号是不会解释变量的
my name is $name

常用的系统变量: 

[root@linux1 script]# cat t1.sh
#!/bin/bash
echo $0      #当前程序名
echo $1  #程序的第一个参数
echo $*  #程序的所有参数名
echo $#  #当前程序的参数个数
echo $?       #程序执行的返回状态
echo $PATH    #系统环境变量的路径
echo $PWD      #当前目录
echo $UID        #当前用的id
[root@linux1 script]# sh t1.sh t1 t2
t1.sh
t1
t1 t2
2
0
/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/root/bin
/script
0

三、脚本输出有颜色的字体:

\033[32m  和 \033[0m  之间的字体会变成绿色

\033[32m  和 \033[1m  下面的所有的字体会变成绿色

\033[31m  和 \033[0m  之间的字体会变成红色

最新文章

  1. IOS 网络-深入浅出(一 )-> 三方SDWebImage
  2. MySQL中优化常用的查询sql语
  3. css3之文本新属性
  4. ACM BUYING FEED
  5. HDOJ并查集题目 HDOJ 1213 HDOJ 1242
  6. SVN Server导项目到本地库时提示"方法OPTIONS失败与无法连接到服务器"
  7. 借鉴网上的winform模仿QQ窗口停靠功能稍作改动
  8. char值码对应大全
  9. 关于Ubuntu远程ssh连接失败的问题
  10. eclipse 安装vrapper vim插件
  11. 面试题 ARC
  12. jquery按钮倒计时
  13. vue vuex的用法
  14. arcgis api for js入门开发系列十六迁徙流动图
  15. 基于Python预测股价
  16. 爬虫系列二(数据清洗--->正则表达式)
  17. ios 容错处理JKDataHelper和AvoidCrash
  18. 使用 PLSQL 连接 Oracle9i 数据库
  19. 如何设置IIS程序池的回收时间,才能最大程度的减少对用户的影响?
  20. Codeforces 1155 D Beautiful Array DP,最大子段和

热门文章

  1. C++纯虚函数
  2. Sql Server 深入的探讨锁机制
  3. java\c程序的内存分配
  4. iframe并排横着显示
  5. 【python】pathlib库
  6. 类似于fopen与fopen64的种种情况
  7. Android之shape属性详解
  8. rsync实时同步文件
  9. OneApm
  10. Oracle11完全卸载方法 deinstall.bat如何用以及如何删除oracle注册表