Linux之shell编程(一)--- shell编程快速入门

1. 为什么要学习Shell编程
  1. Linux运维工程师在进行服务器集群管理时,需要编写Shell程序来进行服务器管理。
  2. 对于JavaEE和Python程序员来说,工作的需要,你的老大会要求你编写一些Shell脚本进行程序或者是服务器的维护,比如编写一个定时备份数据库的脚本。
  3. 对于大数据程序员来说,需要编写Shell程序来管理集群。
2. Shell是什么

Shell是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序,用户可以用Shell来启动、挂起、停止甚至是编写一些程序。
在这里插入图片描述在这里插入图片描述

3. Shell脚本的执行方式
1. 脚本格式要求
  1. 脚本以#!/bin/bash开头
  2. 脚本需要有可执行权限
  3. 编写第一个Shell脚本
    需求说明:创建一个Shell脚本,输出hello shell
    脚本的常用执行方式
    方式1(输入脚本的绝对路径或相对路径)
    说明:首先要赋予hello.sh 脚本的+x权限,再执行脚本
    方式2(sh+脚本)
    说明:不用赋予脚本+x权限,直接执行即可。
[root@localhost100 ~]# mkdir /root/shelltest
[root@localhost100 ~]# cd /root/shelltest/
[root@localhost100 shelltest]# ls
[root@localhost100 shelltest]# vim hello.sh

在这里插入图片描述

[root@localhost100 shelltest]# ll
总用量 4
-rw-r--r--. 1 root root 31 5月  12 16:18 hello.sh
//赋予可执行权限
[root@localhost100 shelltest]# chmod u+x hello.sh 
[root@localhost100 shelltest]# ll
总用量 4
-rwxr--r--. 1 root root 31 5月  12 16:18 hello.sh
[root@localhost100 shelltest]# ./hello.sh 
hello shell
[root@localhost100 shelltest]# /root/shelltest/hello.sh 
hello shell
[root@localhost100 shelltest]# 
//不赋予可执行权限,去掉可执行权限后,执行脚本在前面加上sh 
在前面加上sh 
[root@localhost100 shelltest]# chmod u-x hello.sh
[root@localhost100 shelltest]# ll
总用量 4
-rw-r--r--. 1 root root 31 5月  12 16:18 hello.sh
[root@localhost100 shelltest]# sh hello.sh 
hello shell
[root@localhost100 shelltest]# sh /root/shelltest/hello.sh 
hello shell
[root@localhost100 shelltest]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EOPG

你的鼓励是我创造的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值