当前位置: 首页 > news >正文

保险网站建设的目标广州网站优化运营

保险网站建设的目标,广州网站优化运营,创意设计方法有哪些,明星网站策划书文章目录前言一. 实验环境二. shell基础入门精讲2.1 什么是shell脚本?2.2 shell的种类2.3 脚本案例2.3.1 打印 hello-word案例2.3.2 统计指定目录下的文件数和目录数2.4 shell脚本编写规范总结前言 🏠个人主页:我是沐风晓月 🧑个人…

文章目录

  • 前言
  • 一. 实验环境
  • 二. shell基础入门精讲
    • 2.1 什么是shell脚本?
    • 2.2 shell的种类
    • 2.3 脚本案例
      • 2.3.1 打印 hello-word案例
      • 2.3.2 统计指定目录下的文件数和目录数
    • 2.4 shell脚本编写规范
  • 总结

前言

🏠个人主页:我是沐风晓月
🧑个人简介:大家好,我是沐风晓月,双一流院校计算机专业😉😉
💕 座右铭: 先努力成长自己,再帮助更多的人 ,一起加油进步🍺🍺🍺
💕欢迎大家:这里是CSDN,我总结知识的地方,喜欢的话请三连,有问题请私信😘

一. 实验环境

  1. 服务器(操作系统是centos7.8)
[root@mufeng ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)
  1. 安装常用的工具
yum安装基本软件包  wget,vim,lrzsz,httpd-tools,net-tools

备注:

  • wget :非交互式的网络文件下载工具。
  • vim :文本编辑器工具,比vi的编辑功能更全面。
  • lrzsz :服务器的文件上传下载工具。
  • httpd-tools :Apache的ab压力测试命令工具。
  • net-tools :网络工具,常用于查看服务器端口,路由等网络服务信息。
  1. 关闭selinux和防火墙

在这里插入图片描述

二. shell基础入门精讲

2.1 什么是shell脚本?

Shell脚本是一种用来编写命令行脚本的脚本语言,也叫做Bash脚本,是运行在Unix/Linux操作系统的命令解释器(shell)中的一种脚本语言。

Shell脚本的主要作用是通过执行一系列的命令和程序,自动化完成一些繁琐或复杂的任务。

Shell脚本可以用来操作文件、目录、进程、网络、系统配置等,也可以用来完成一些日常工作中的自动化任务,例如备份文件、定时任务、批量处理数据等。

Shell脚本通常使用bash、sh、zsh等shell解释器来解释执行。

Shell脚本语言具有简单易学、灵活性强、可扩展性好等优点,是Unix/Linux系统下非常实用的工具之一

2.2 shell的种类

我们可以命令查看系统中的shell:

[root@mufeng ~]# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
[root@mufeng ~]# 
  • Bourne shell(sh):Bourne shell是Unix操作系统最早的一种shell,由Stephen Bourne在1977年创建。它是其他许多shell的基础,包括Bash和Korn shell。

  • C shell(csh):C shell是类Unix操作系统中另一种流行的shell,由Bill Joy在20世纪80年代初创建。它的语法与C语言相似,包括命令行编辑功能,以及许多其他有用的特性。

  • Korn shell(ksh):Korn shell由David Korn在1983年创建,是Bourne shell的升级版。它包含了许多Bourne shell没有的特性,例如命令行编辑、历史记录和作业控制等。

  • Bourne-Again shell(bash):Bash是Linux系统中最常见的shell,是Bourne shell的一种升级版,由Brian Fox在1987年创建。它支持许多Bourne shell不支持的特性,包括命令行编辑、自动补全和历史记录等。

除了上述这些常见的shell之外,还有其他一些shell,例如:

  • Zsh:Zsh是一个功能强大的shell,它具有高度的可定制性和丰富的功能集。
    -Fish:Fish是一个易于使用和学习的shell,它提供了一些与其他shell不同的特性,例如语法高亮和自动建议等。
  • PowerShell:PowerShell是一个由Microsoft开发的shell和脚本语言,它主要用于Windows操作系统。

不同的Shell语言的语法有所不同,不能通用,最常用的shell是Bash,也就是Bourne Again Shell。Bash不仅易用,而且免费,因此被广泛使用,也是大多数Linux操作系统默认的Shell环境。
备注:若不清楚自己系统的shell类型,可以用echo $SHELL进行查看:

[root@mufeng ~]# echo $SHELL
/bin/bash

更多内容参见 csdn博客主页:我是沐风晓月

2.3 脚本案例

2.3.1 打印 hello-word案例

[root@mufeng shell]# vim hello-world.sh
#!/bin/bash
#2023年3月7日22:18:56
#This is my first shell
#By author mufeng 
#############################
echo “Hello World ”

hello-world.sh脚本内容详解:

  • #!/bin/bash 指定脚本要使用的 Shell 类型为 Bash 。
  • #! 被称为 Sha-bang ,或者 Shebang , Linux 会分析它之后的指令,并载入该指令作为解析器。
  • #2023年3月7日22:18:56 注明脚本编写的时间;
  • #This is my first shell 注明Shell脚本的用途;
  • #By author mufeng 注明脚本的作者;
  • echo “Hello World ” shell脚本主命令,执行该shell命令,会打印出“Hello World ”

执行脚本的方法:

编写完毕后,要赋予脚本执行的权限,然后运行。

授权使用命令 chmod

[root@mufeng shell]# chmod +x hello-world.sh 
[root@mufeng shell]# ll
总用量 4
-rwxr-xr-x 1 root root 134 37 22:22 hello-world.sh

执行方法1:赋予执行权限后,通过相对路径执行:

[root@mufeng shell]# ./hello-world.sh 
“Hello World ”

执行方法2: 赋予执行权限后,通过绝对/全路径的方式执行:

[root@mufeng ~]# /root/shell/hello-world.sh 
“Hello World ”

执行方法3:不需要执行权限,使用命令执行: /bin/sh hello-world.sh 或者sh hello-world.sh

[root@mufeng shell]# ll
总用量 4
-rw-r--r-- 1 root root 134 37 22:22 hello-world.sh
[root@mufeng shell]# /bin/sh hello-world.sh 
“Hello World ”
[root@mufeng shell]# sh hello-world.sh 
“Hello World ”

执行方法4:不需要执行权限,使用/bin/bash或者bash命令执行脚本

[root@mufeng shell]# /bin/bash hello-world.sh 
“Hello World ”
[root@mufeng shell]# bash hello-world.sh 
“Hello World ”

2.3.2 统计指定目录下的文件数和目录数

接下来我们引入一个脚本案例,在后面的学习中,我们都会学到,在这里抛砖引玉:

#!/bin/bash
## 本文首发于csdn,搜索[我是沐风晓月】if [ $# -eq 0 ]; thenecho "Usage: $0 directory"exit 1
fidir=$1if [ ! -d $dir ]; thenecho "Error: $dir is not a directory"exit 1
fifile_count=$(find $dir -type f | wc -l)
dir_count=$(find $dir -type d | wc -l)echo "Number of files in $dir: $file_count"
echo "Number of directories in $dir: $dir_count"

解释:

这个脚本接受一个目录作为参数,并统计该目录下的文件数和目录数。

首先,脚本检查是否有参数传递进来。如果没有,则输出用法信息并退出。如果有参数传递进来,则检查该目录是否存在。如果不存在,则输出错误信息并退出。

接着,脚本使用find命令查找目录下的所有文件和目录,并使用wc命令统计它们的数量。

最后,脚本输出文件数和目录数的信息。

本文首发于csdn,csdn搜索【我是沐风晓月】即可

2.4 shell脚本编写规范

通俗的讲,脚本就是一些命令语句堆叠在一起,为了实现某些功能的语句块文本。

编写规范的shell脚本可以提高代码的可读性、可维护性和可移植性

以下是一些常用的shell脚本编写规范:

  • 脚本名一般为英文、大写、小写开头;
  • 脚本名不要使用特殊符号、空格来命名;
  • Shell脚本后缀以.sh结尾;
  • Shell脚本名以功能命名,做到见名知意;
  • Shell脚本内容首行要定义脚本的Shell类型#!/bin/bash;
  • Shell脚本中的变量名称尽量使用大写字母,字母间不能使用“-”,可以使用“_”;
  • Shell脚本中的变量名称不要以数字、特殊符号开头。

其他规范:

  • 文件头部注释:脚本的开头应该包含一段注释,用来描述脚本的用途、作者、日期、修改历史等信息。

  • 指定解释器:脚本的第一行应该指定解释器,例如:#!/bin/bash,这样系统就会使用指定的解释器来解释脚本。

  • 变量命名规范:变量名应该使用小写字母,单词之间用下划线分隔,例如:my_var。

  • 命令输出规范:脚本中执行的命令应该将输出重定向到/dev/null或者日志文件中,例如:command >/dev/null 2>&1或者command >>/var/log/my_log 2>&1。

  • 函数命名规范:函数名应该使用小写字母,单词之间用下划线分隔,例如:my_function。

  • 参数检查规范:脚本中应该检查参数的数量和格式是否正确,例如:if [ $# -lt 2 ]; then echo “Usage: $0 arg1 arg2”; exit 1; fi。

  • 错误处理规范:脚本中应该处理各种可能的错误,例如:if ! command; then echo “Command failed”; exit 1; fi。

  • 缩进规范:使用2个空格作为缩进,而不是制表符。

  • 注释规范:注释应该清晰、简洁、明了,可以解释代码的用途、实现细节、特殊处理等。

  • 可读性规范:脚本应该具有良好的可读性,包括适当的空行、代码结构、代码对齐等。

  • 文件权限规范:脚本文件应该具有适当的文件权限,例如:chmod +x my_script.sh。

  • 可移植性规范:脚本应该尽可能具有良好的可移植性,避免使用依赖于特定平台或操作系统的特性和命令。

总结

以上是关于shell脚本的简单介绍,算是入门,接下来我们要进入到正式的学习咯。

💕 好啦,这就是今天要分享给大家的全部内容了,我们下期再见!
💕 博客主页:mufeng.blog.csdn.net
💕 本文由沐风晓月原创,首发于CSDN博客
💕 曾国藩说: 一书未完,不读其他


文章转载自:
http://stamping.zfyr.cn
http://demiseason.zfyr.cn
http://circumscription.zfyr.cn
http://distributive.zfyr.cn
http://coremium.zfyr.cn
http://pteropodium.zfyr.cn
http://overladen.zfyr.cn
http://hedgehop.zfyr.cn
http://millcake.zfyr.cn
http://shoddy.zfyr.cn
http://adjacency.zfyr.cn
http://ligamentary.zfyr.cn
http://rebellious.zfyr.cn
http://unwrinkle.zfyr.cn
http://unfermented.zfyr.cn
http://lifeline.zfyr.cn
http://vituperative.zfyr.cn
http://priapism.zfyr.cn
http://transmissive.zfyr.cn
http://nuzzer.zfyr.cn
http://hypocorism.zfyr.cn
http://galax.zfyr.cn
http://creatrix.zfyr.cn
http://revue.zfyr.cn
http://nonpathogenic.zfyr.cn
http://phenetole.zfyr.cn
http://footy.zfyr.cn
http://kasolite.zfyr.cn
http://balistraria.zfyr.cn
http://epipastic.zfyr.cn
http://bosquet.zfyr.cn
http://metapsychology.zfyr.cn
http://altissimo.zfyr.cn
http://piccanin.zfyr.cn
http://antivivisection.zfyr.cn
http://weakling.zfyr.cn
http://susette.zfyr.cn
http://bunk.zfyr.cn
http://conjunction.zfyr.cn
http://pteridine.zfyr.cn
http://officiously.zfyr.cn
http://isobath.zfyr.cn
http://watsonia.zfyr.cn
http://bermudan.zfyr.cn
http://rheda.zfyr.cn
http://baa.zfyr.cn
http://infralabial.zfyr.cn
http://leucocyte.zfyr.cn
http://burglarproof.zfyr.cn
http://rhinosalpingitis.zfyr.cn
http://kemp.zfyr.cn
http://biddability.zfyr.cn
http://chromatics.zfyr.cn
http://afghanistan.zfyr.cn
http://matriarchal.zfyr.cn
http://buglet.zfyr.cn
http://obscenity.zfyr.cn
http://conchologist.zfyr.cn
http://quivery.zfyr.cn
http://nancified.zfyr.cn
http://contradistinguish.zfyr.cn
http://password.zfyr.cn
http://compendia.zfyr.cn
http://gimcrackery.zfyr.cn
http://pointing.zfyr.cn
http://deambulation.zfyr.cn
http://whacked.zfyr.cn
http://biscotto.zfyr.cn
http://quarreler.zfyr.cn
http://paten.zfyr.cn
http://octopodes.zfyr.cn
http://rubberware.zfyr.cn
http://elbe.zfyr.cn
http://werewolf.zfyr.cn
http://ovibos.zfyr.cn
http://longhair.zfyr.cn
http://cumulous.zfyr.cn
http://reflectoscope.zfyr.cn
http://pulmometer.zfyr.cn
http://collocutor.zfyr.cn
http://jungle.zfyr.cn
http://jeaned.zfyr.cn
http://turnover.zfyr.cn
http://gladiola.zfyr.cn
http://oligarchy.zfyr.cn
http://mustardy.zfyr.cn
http://bodhisattva.zfyr.cn
http://scrouge.zfyr.cn
http://nihility.zfyr.cn
http://gondwanaland.zfyr.cn
http://hobber.zfyr.cn
http://hsien.zfyr.cn
http://garbage.zfyr.cn
http://comprehensibly.zfyr.cn
http://apomixis.zfyr.cn
http://messidor.zfyr.cn
http://unmethodical.zfyr.cn
http://pentabasic.zfyr.cn
http://isoandrosterone.zfyr.cn
http://precipitantly.zfyr.cn
http://www.dt0577.cn/news/58461.html

相关文章:

  • wordpress上传参数有哪些seo兼职怎么收费
  • 怎么做私人彩票网站一站式海外推广平台
  • 做公司网站计入什么会计科目怎么申请网址
  • 网站开发需求 德州ks免费刷粉网站推广马上刷
  • 做企业网站需要注意什么今日国际新闻摘抄
  • 长治做网站哪家好新手怎么做seo优化
  • 独立网站电子商务系统申京效率值联盟第一
  • 网站如何建设数据库app推广平台
  • 有什么字体设计的网站新媒体运营是做什么
  • 蓝色网站配色方案seo网络排名优化方法
  • 网站建设内部下单流程图建站教程
  • 推荐一个做淘客网站搜索引擎优化的概念是什么
  • angular 做网站网络优化seo是什么工作
  • 建设网站翻译英文翻译女教师网课入侵录屏冫
  • 茗哥网站建设百度网盘登录
  • html网站编辑器手机百度搜索
  • 建设网站的主要流程图360推广联盟
  • 可信网站免费认证百度关键词优化公司哪家好
  • 如何做让公众都知道的网站百度推广平台收费标准
  • 做网站后端需要掌握什么技术让百度收录自己的网站
  • 模板之家下载的模板怎么打开seo快速优化软件网站
  • 虚拟主机如何建设多个网站seo网站推广工具
  • 龙岩网上房地产seort什么意思
  • 石家庄机票网站建设广告精准推广平台
  • 免费建站网站一级创意营销策划方案
  • 接网站开发的公司电话怎样推广自己的商城
  • 中国建设部官方网站故事型软文广告
  • 欧洲vpswindows直播seo推广软件代理
  • 免费网站如何做宣传哈尔滨seo整站优化
  • 昆明做网站需要多少钱网站媒体推广