1.脚本格式
脚本以#!/bin/bash开头(指定解析器)
2.第一个Shell脚本:helloworld
(1)需求:创建一个Shell脚本,输出helloworld
(2)案例实操:
[atguigu@hadoop101 datas] vi helloworld.sh
在helloworld.sh中输入如下内容
!/bin/bash
echo "helloworld"
(3)脚本的常用执行方式
第一种:采用bash或sh+脚本的相对路径或绝对路径(不用赋予脚本+x权限)
sh+脚本的相对路径
[atguigu@hadoop101 datas] sh /home/atguigu/datas/helloworld.sh
helloworld
bash+脚本的相对路径
[atguigu@hadoop101 datas] bash /home/atguigu/datas/helloworld.sh
Helloworld
第二种:采用输入脚本的绝对路径或相对路径执行脚本(必须具有可执行权限+x)
(a)首先要赋予helloworld.sh 脚本的+x权限
[atguigu@hadoop101 datas] ./helloworld.sh
Helloworld
绝对路径
[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)了解更多。
网友评论