Shell脚本学习
2014-04-13 22:02
330 查看
Shell脚本学习:
todd@todd-virtual-machine:~/shellfile/work01$vi helloword.sh 新建一个helloworld.sh的shell文件
todd@todd-virtual-machine:~/shellfile/work01$ls
helloword.sh
todd@todd-virtual-machine:~/shellfile/work01$chmod u+x helloword.sh 修改文件的权限
todd@todd-virtual-machine:~/shellfile/work01$ls (u+x代表用户可用)
helloword.sh
脚本注释用 # 不用//
Shell编程中双引号“” 单引号‘ ‘ 倒引号 ` ` 之间的区别
todd@todd-virtual-machine:~/shellfile/work01/03$vi quote.sh
todd@todd-virtual-machine:~/shellfile/work01/03$chmod u+x quote.sh 修改权限
todd@todd-virtual-machine:~/shellfile/work01/03$ls
quote.sh
todd@todd-virtual-machine:~/shellfile/work01/03$./quote.sh 执行脚本程序
today is saturday 是显示log的定义的变量值
today is $log 原封不动的吧$log 输出
today is 2014年 04月 13日 星期日 14:41:44 CST 执行过得date然后输出出来。
控制语句:
If判断语句
While 语句
Read语句 输入任意n值,计算出1+2+3+ …+n的值
cut 命令
todd@todd-virtual-machine:~/shellfile/work01/07$vi city
todd@todd-virtual-machine:~/shellfile/work01/07$cut -c 3-6 city
提取city中的第3到第6个字符
ijin
angh
anji
todd@todd-virtual-machine:~/shellfile/work01/07$sort city 顺序排列
beijing 010
shanghai 021
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$sort -r city 反序排列
tianjing 022
shanghai 021
beijing 010
todd@todd-virtual-machine:~/shellfile/work01/07$sort -k 2 city 对文件的第二列排序
beijing 010
shanghai 021
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$vi city
todd@todd-virtual-machine:~/shellfile/work01/07$cat city
beijing 010
beijing 010
shanghai 021
tianjing 022
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$sort city|uniq 将重复的部分删除
beijing 010
shanghai 021
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$tr "bhs" "BHS"<city 从定向输出讲所有bhs替换为BHS
Beijing 010
Beijing 010
SHangHai 021
tianjing 022
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$tr "bei" "[x*]"<city
xxxjxng 010
xxxjxng 010
shanghax 021
txanjxng 022
txanjxng 022
todd@todd-virtual-machine:~/shellfile/work01/07$tr --delete "ei"<city 讲ei删除输出
bjng 010
bjng 010
shangha 021
tanjng 022
tanjng 022
todd@todd-virtual-machine:~/shellfile/work01/07$wc city 查看文件信息
5 10 80 city
5带表有5行,10个单词,80个字节,文件名为city
todd@todd-virtual-machine:~/shellfile/work01/07$wc -c city 一共有80个字节
80 city
todd@todd-virtual-machine:~/shellfile/work01/07$wc -l city 用有5行
5 city
todd@todd-virtual-machine:~/shellfile/work01/07$wc -L city 最长的一行有15个字符
15 city
todd@todd-virtual-machine:~/shellfile/work01/07$wc -w city 有10个单词
10 city
todd@todd-virtual-machine:~/shellfile/work01/07$exper substr "hello worl" 1 5 从hello world中提取第1到第5个字符
todd@todd-virtual-machine:~$ seq 8 输出第1到8的等差数列
1
2
3
4
5
6
7
8
todd@todd-virtual-machine:~$ seq 9 -3 0 输出9-0的以3为递减值的等差数列
9
6
3
0
todd@todd-virtual-machine:~$ printenv 查看已定义的系统变量
todd@todd-virtual-machine:~$ ls –l 查看当前目录下的详细文件信息
总用量 59852
-rw-r--r-- 1 todd todd 8980 3月 28 17:50 examples.desktop
drwxr-xr-x 5 todd todd 4096 4月 13 12:00 shellfile
drwxr-xr-x 7 todd todd 4096 4月 12 13:35 test
-rw-r--r-- 1 todd todd 73 4月 12 10:55 test02
drwxr-xr-x 3 todd todd 4096 4月 24 2013 vimconfig
-rwxrw-rw- 1 todd todd 559899 3月 28 17:09 vimconfig.tar.bz2
-rw-r--r-- 1 todd todd 60654199 8月 27 2013 VMwareTools-9.6.0-1294478.tar.gz
drwxr-xr-x 7 todd todd 4096 8月 27 2013 vmware-tools-distrib
-rw-r--r-- 1 todd todd 163 4月 13 10:30 week
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 公共的
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 模板
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 视频
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 图片
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 文档
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 下载
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 音乐
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 桌面
todd@todd-virtual-machine:~$ alias ll='ls -l'
也可以将ls –l 简化定义为ll(关闭终端后,在另一个终端下使用这个别名是没有效果的,如果要然它一直有效,就需要将别名定义在bash下)
todd@todd-virtual-machine:~$ ll 再次输入时ll就等同于ls –l
todd@todd-virtual-machine:~/shellfile/work01$vi helloword.sh 新建一个helloworld.sh的shell文件
todd@todd-virtual-machine:~/shellfile/work01$ls
helloword.sh
todd@todd-virtual-machine:~/shellfile/work01$chmod u+x helloword.sh 修改文件的权限
todd@todd-virtual-machine:~/shellfile/work01$ls (u+x代表用户可用)
helloword.sh
脚本注释用 # 不用//
Shell编程中双引号“” 单引号‘ ‘ 倒引号 ` ` 之间的区别
todd@todd-virtual-machine:~/shellfile/work01/03$vi quote.sh
todd@todd-virtual-machine:~/shellfile/work01/03$chmod u+x quote.sh 修改权限
todd@todd-virtual-machine:~/shellfile/work01/03$ls
quote.sh
todd@todd-virtual-machine:~/shellfile/work01/03$./quote.sh 执行脚本程序
today is saturday 是显示log的定义的变量值
today is $log 原封不动的吧$log 输出
today is 2014年 04月 13日 星期日 14:41:44 CST 执行过得date然后输出出来。
控制语句:
If判断语句
While 语句
Read语句 输入任意n值,计算出1+2+3+ …+n的值
cut 命令
todd@todd-virtual-machine:~/shellfile/work01/07$vi city
todd@todd-virtual-machine:~/shellfile/work01/07$cut -c 3-6 city
提取city中的第3到第6个字符
ijin
angh
anji
todd@todd-virtual-machine:~/shellfile/work01/07$sort city 顺序排列
beijing 010
shanghai 021
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$sort -r city 反序排列
tianjing 022
shanghai 021
beijing 010
todd@todd-virtual-machine:~/shellfile/work01/07$sort -k 2 city 对文件的第二列排序
beijing 010
shanghai 021
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$vi city
todd@todd-virtual-machine:~/shellfile/work01/07$cat city
beijing 010
beijing 010
shanghai 021
tianjing 022
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$sort city|uniq 将重复的部分删除
beijing 010
shanghai 021
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$tr "bhs" "BHS"<city 从定向输出讲所有bhs替换为BHS
Beijing 010
Beijing 010
SHangHai 021
tianjing 022
tianjing 022
todd@todd-virtual-machine:~/shellfile/work01/07$tr "bei" "[x*]"<city
xxxjxng 010
xxxjxng 010
shanghax 021
txanjxng 022
txanjxng 022
todd@todd-virtual-machine:~/shellfile/work01/07$tr --delete "ei"<city 讲ei删除输出
bjng 010
bjng 010
shangha 021
tanjng 022
tanjng 022
todd@todd-virtual-machine:~/shellfile/work01/07$wc city 查看文件信息
5 10 80 city
5带表有5行,10个单词,80个字节,文件名为city
todd@todd-virtual-machine:~/shellfile/work01/07$wc -c city 一共有80个字节
80 city
todd@todd-virtual-machine:~/shellfile/work01/07$wc -l city 用有5行
5 city
todd@todd-virtual-machine:~/shellfile/work01/07$wc -L city 最长的一行有15个字符
15 city
todd@todd-virtual-machine:~/shellfile/work01/07$wc -w city 有10个单词
10 city
todd@todd-virtual-machine:~/shellfile/work01/07$exper substr "hello worl" 1 5 从hello world中提取第1到第5个字符
todd@todd-virtual-machine:~$ seq 8 输出第1到8的等差数列
1
2
3
4
5
6
7
8
todd@todd-virtual-machine:~$ seq 9 -3 0 输出9-0的以3为递减值的等差数列
9
6
3
0
todd@todd-virtual-machine:~$ printenv 查看已定义的系统变量
todd@todd-virtual-machine:~$ ls –l 查看当前目录下的详细文件信息
总用量 59852
-rw-r--r-- 1 todd todd 8980 3月 28 17:50 examples.desktop
drwxr-xr-x 5 todd todd 4096 4月 13 12:00 shellfile
drwxr-xr-x 7 todd todd 4096 4月 12 13:35 test
-rw-r--r-- 1 todd todd 73 4月 12 10:55 test02
drwxr-xr-x 3 todd todd 4096 4月 24 2013 vimconfig
-rwxrw-rw- 1 todd todd 559899 3月 28 17:09 vimconfig.tar.bz2
-rw-r--r-- 1 todd todd 60654199 8月 27 2013 VMwareTools-9.6.0-1294478.tar.gz
drwxr-xr-x 7 todd todd 4096 8月 27 2013 vmware-tools-distrib
-rw-r--r-- 1 todd todd 163 4月 13 10:30 week
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 公共的
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 模板
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 视频
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 图片
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 文档
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 下载
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 音乐
drwxr-xr-x 2 todd todd 4096 3月 28 18:24 桌面
todd@todd-virtual-machine:~$ alias ll='ls -l'
也可以将ls –l 简化定义为ll(关闭终端后,在另一个终端下使用这个别名是没有效果的,如果要然它一直有效,就需要将别名定义在bash下)
todd@todd-virtual-machine:~$ ll 再次输入时ll就等同于ls –l
相关文章推荐
- Linux系统Shell脚本的入门学习
- 菜鸟shell 脚本学习日记
- Shell脚本学习笔记
- 学习笔记之Shell脚本的输出重定向
- shell学习 - 处理脚本的多参数输入
- Shell脚本学习(一)Shell命令基础
- shell脚本学习笔记 (文本处理器AWK)
- Shell脚本实现每个工作日定时执行指定程序(学习记录)
- linux学习 shell脚本
- Shell脚本学习笔记(二)--变量
- Shell脚本学习心得
- shell学习(一):统计文本行数脚本
- [linux-shell]脚本攻略学习笔记
- shell脚本的学习1-截取字符串
- shell脚本学习笔记
- linux学习(六) shell脚本(3)
- shell脚本交互:expect学习笔记及实例详解
- shell脚本学习案例
- shell脚本学习
- Linux-Shell脚本编程-学习-8-函数