大数据开发岗为什么要学习Shell呢?
1)需要看懂大数据运维岗人员编写的Shell程序。
2)偶尔会编写一些简单Shell程序来管理集群、提高开发效率

艺多不压身

Shell是一个命令行解释器,它接受应用程序/用户命令,然后调用操作系统内核
Shell还是一个功能相当强大的编程语言,易编写,易调试,灵活性强

Shell解析器
Linux提供的Shell解析器有:

[root@Bigdata ~]$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

Centos默认的解析器是bash

[root@Bigdata bin]$ echo $SHELL
/bin/bash

Shell脚本入门
1.脚本格式
脚本以#!/bin/bash开头(指定解析器)
2.第一个Shell脚本:helloworld
(1)需求:创建一个Shell脚本,输出helloworld
(2)案例实操:

[root@Bigdata shell]$ touch helloworld.sh
[root@Bigdata shell]$ vi helloworld.sh

在helloworld.sh中输入如下内容

#!/bin/bash
echo "helloworld"

(3)脚本的常用执行方式
第一种:采用bash或sh+脚本的相对路径或绝对路径(不用赋予脚本+x权限)
sh+脚本的相对路径

[root@Bigdata shell]$ sh helloworld.sh
helloworld

sh+脚本的绝对路径

[root@Bigdata shell]$ sh /opt/shell/helloworld.sh
helloworld

bash+脚本的相对路径

[root@Bigdata shell]$ bash helloworld.sh
helloworld

bash+脚本的绝对路径

[root@Bigdata shell]$ bash /opt/shell/helloworld.sh
helloworld

第二种:采用输入脚本的绝对路径或相对路径执行脚本(必须具有可执行权限+x)
(a)首先要赋予helloworld.sh 脚本的+x权限

[root@Bigdata shell]$ chmod 777 helloworld.sh

(b)执行脚本
相对路径

[root@Bigdata shell]$ ./helloworld.sh
helloworld

绝对路径

[root@Bigdata shell]$ /opt/shell/helloworld.sh
helloworld

注意:第一种执行方法,本质是bash解析器帮你执行脚本,所以脚本本身不需要执行权限。第二种执行方法,本质是脚本需要自己执行,所以需要执行权限。

3.第二个Shell脚本:多命令处理
(1)需求:
在/opt/shell/目录下创建一个huan.txt,在huan.txt文件中增加“huanhuan”。
(2)案例实操:

[root@Bigdata shell]$ touch huan.sh
[root@Bigdata shell]$ vim huan.sh

在huan.sh中输入如下内容

#!/bin/bash

cd /opt/shel
touch huan.txt
echo "huanhuan" >> huan.txt

最新文章

  1. 【BZOJ1911】[Apio2010]特别行动队 斜率优化DP
  2. python字符串方法的简单使用
  3. CentOS搭建VPN
  4. Yii2.0中文开发向导——Yii2中多表关联查询(join、joinwith)
  5. DOM中 property 和 attribute 详解
  6. hdu1116 欧拉回路
  7. LabVIEW设计模式系列——资源关闭后错误处理
  8. POJ题目细究
  9. git变基、冲突解决
  10. Boost::Asio::Error的用法浅析
  11. CF 604C Alternative Thinking#贪心
  12. USACO奶牛博览会(DP)
  13. json-sever 配置与应用
  14. HDU 1228(字符串处理)
  15. 下拉框、下拉控件之Select2。自动补全的使用
  16. Spring Security 整合freemaker 实现简单登录和角色控制
  17. 移除元素-leetcode-27
  18. Wordpress 更新时 不输入ftp相关信息的方法
  19. Jenkins之发送html附件邮件配置
  20. linux分享四:cron系统

热门文章

  1. Go操作Redis实战
  2. java中根据后端返回的数据加载table列表
  3. 什么是CDN?哪些是流行的jQuery CDN?使用CDN有什么好处?
  4. Service Mesh——微服务中的流量管理中间件
  5. 初探JAVA内部类细节一
  6. 【Go】四舍五入在go语言中为何如此困难
  7. three.js 显示中文字体 和 tween应用
  8. git 合并多次commit
  9. Phoneix(三)HBase集成Phoenix创建二级索引
  10. uni-app 顶部tabbar切换