美文网首页Shell
尚硅谷大数据技术之Shell 第3章 Shell脚本入门

尚硅谷大数据技术之Shell 第3章 Shell脚本入门

作者: 尚硅谷教育 | 来源:发表于2018-10-31 15:03 被阅读36次

1.脚本格式
脚本以#!/bin/bash开头(指定解析器)
2.第一个Shell脚本:helloworld
(1)需求:创建一个Shell脚本,输出helloworld
(2)案例实操:
[atguigu@hadoop101 datas]touch helloworld.sh [atguigu@hadoop101 datas] vi helloworld.sh

在helloworld.sh中输入如下内容

!/bin/bash

echo "helloworld"
(3)脚本的常用执行方式
第一种:采用bash或sh+脚本的相对路径或绝对路径(不用赋予脚本+x权限)
sh+脚本的相对路径
[atguigu@hadoop101 datas]sh helloworld.sh Helloworld sh+脚本的绝对路径 [atguigu@hadoop101 datas] sh /home/atguigu/datas/helloworld.sh
helloworld
bash+脚本的相对路径
[atguigu@hadoop101 datas]bash helloworld.sh Helloworld bash+脚本的绝对路径 [atguigu@hadoop101 datas] bash /home/atguigu/datas/helloworld.sh
Helloworld
第二种:采用输入脚本的绝对路径或相对路径执行脚本(必须具有可执行权限+x)
(a)首先要赋予helloworld.sh 脚本的+x权限
[atguigu@hadoop101 datas]chmod 777 helloworld.sh (b)执行脚本 相对路径 [atguigu@hadoop101 datas] ./helloworld.sh
Helloworld
绝对路径
[atguigu@hadoop101 datas]/home/atguigu/datas/helloworld.sh Helloworld 注意:第一种执行方法,本质是bash解析器帮你执行脚本,所以脚本本身不需要执行权限。第二种执行方法,本质是脚本需要自己执行,所以需要执行权限。 3.第二个Shell脚本:多命令处理 (1)需求: 在/home/atguigu/目录下创建一个banzhang.txt,在banzhang.txt文件中增加“I love cls”。 (2)案例实操: [atguigu@hadoop101 datas] touch batch.sh
[atguigu@hadoop101 datas]$ vi batch.sh

在batch.sh中输入如下内容

!/bin/bash

cd /home/atguigu
touch cls.txt
echo "I love cls" >>cls.txt

本教程由尚硅谷教育大数据研究院出品,如需转载请注明来源,欢迎大家关注尚硅谷公众号(atguigu)了解更多。

相关文章

  • 尚硅谷大数据技术之Shell 第3章 Shell脚本入门

    1.脚本格式脚本以#!/bin/bash开头(指定解析器)2.第一个Shell脚本:helloworld(1)需求...

  • Shell入门笔记

    Shell脚本:Linux Shell脚本学习指南菜鸟教程 - Shell教程Linux入门 - Shell脚本是...

  • Shell 概述

    学习 Shell 主要包括的内容: Shell 脚本入门 Shell 变量 Shell 内置命令 Shell 运算...

  • Shell脚本编程30分钟入门

    Shell脚本编程30分钟入门 什么是Shell脚本 示例 看个例子吧: 示例解释 第1行:指定脚本解释器,这里是...

  • Lesson-42 Shell(非原创,搬运自 Github)

    Shell脚本编程30分钟入门 什么是Shell脚本 示例 看个例子吧: 示例解释 第1行:指定脚本解释器,这里是...

  • Shell脚本编程30分钟入门

    作者:qinjx原文地址:Shell脚本编程30分钟入门 什么是Shell脚本 示例 看个例子吧: 示例解释 第1...

  • shell脚本

    shell入门 脚本格式入门 脚本以!/bin/bash开头,指定解析器 第一个shell脚本 需求 创建shel...

  • 大数据学习-Linux Shell脚本快速入门

    批量处理数据,难免会有在集群中使用Shell脚本,自动跑程序,下面快速入门Shell脚本编程,本文解决一下问题: ...

  • shell入门学习(1)——语法基础

    本文为转载,原文:shell入门学习(1)——语法基础 介绍 Shell Script,Shell脚本与Windo...

  • 2019-09-19

    Shell 概述 Shell 解析器 查看系统shell解析器 默认解析器为bash Shell 脚本入门 新建h...

网友评论

    本文标题:尚硅谷大数据技术之Shell 第3章 Shell脚本入门

    本文链接:https://www.haomeiwen.com/subject/josatqtx.html