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

asp.net 网站计数器做财经比较好的网站有哪些

asp.net 网站计数器,做财经比较好的网站有哪些,国家信息公示系统官网,网站直播间怎么做文章目录 1. 特殊变量补充2. 变量扩展-变量子串2.1 获取变量字符的长度2.2 给变量设置默认值 3. 命令3.1 dirname3.2 basename3.3 cut 4. 条件测试命令:[]4.1 逻辑运算符4.2 文件测试4.3 案例:书写脚本-检查文件类型4.4 逻辑运算4.5 案例:书写…

文章目录

  • 1. 特殊变量补充
  • 2. 变量扩展-变量子串
    • 2.1 获取变量字符的长度
    • 2.2 给变量设置默认值
  • 3. 命令
    • 3.1 dirname
    • 3.2 basename
    • 3.3 cut
  • 4. 条件测试命令:[]
    • 4.1 逻辑运算符
    • 4.2 文件测试
    • 4.3 案例:书写脚本-检查文件类型
    • 4.4 逻辑运算
    • 4.5 案例:书写脚本-检查服务是否正在运行或是开机自启动
    • 4.6 增强版条件测试命令:[[]]
    • 4.7 面试题:[]与[[]]的区别?
  • 5. 字符串比较
    • 5.1 案例:书写脚本-检查服务是否正在运行和开机自启动
  • 6. 多分支:if、case
    • 6.1 案例-统计根分区磁盘使用率,60-70输出警告,70-80输出需要处理,80-95输出需要及时处理,965以上输出立刻处理
    • 6.2 案例:判断系统类型
  • 7. 踩坑记录
    • 1. 条件测试时,变量要加上双引号
  • 8. 思维导图

1. 特殊变量补充

  • $$:获取当前脚本的pid
  • $_:获取上一个命令的最后一个参数;在命令行中可以使用Esc+.快捷键

2. 变量扩展-变量子串

  • 用于对变量处理、加工

2.1 获取变量字符的长度

[root@aliyun-ubuntu ~]# name=skx
[root@aliyun-ubuntu ~]# echo $name
skx
[root@aliyun-ubuntu ~]# echo ${#name}
3

2.2 给变量设置默认值

格式说明
${para:-word}变量para没定义或为空时,word作为默认值,不修改原内容
${para:=word}变量para没定义或为空时,word作为默认值,修改原内容
  • ${para:-word}
# 变量为空
[root@aliyun-ubuntu ~]# echo $name# 为变量设置默认值,不修改原内容
[root@aliyun-ubuntu ~]# echo ${name:-root}
root
[root@aliyun-ubuntu ~]# echo $name
  • ${para:=word}
[root@aliyun-ubuntu ~]# echo $name # 为空变量设置默认值,并修改原内容
[root@aliyun-ubuntu ~]# echo ${name:=skx}
skx
[root@aliyun-ubuntu ~]# echo $name
skx

3. 命令

3.1 dirname

  • 显示路径前缀
[root@aliyun-ubuntu ~]# dirname /etc/passwd
/etc
[root@aliyun-ubuntu ~]# dirname /etc/ssh/ssh_config
/etc/ssh

3.2 basename

  • 显示路径后缀
[root@aliyun-ubuntu ~]# basename /etc/passwd
passwd
[root@aliyun-ubuntu ~]# basename ./snap/lxd/
lxd

3.3 cut

  • -c n-m:截取字符串的第n到第m个字符
[root@aliyun-ubuntu ~]# string=1234567890
[root@aliyun-ubuntu ~]# echo $string |cut -c 5
5
[root@aliyun-ubuntu ~]# echo $string |cut -c 5-8
5678

4. 条件测试命令:[]

[ ]或test,用于检查文件属性、字符串比较、数值比较等逻辑判断。它是 Shell 脚本中常见的条件判断语法之一。

  • []内部必须用空格分隔

4.1 逻辑运算符

  • 逻辑运算符不能在[]内使用
  • &&:并且,前面命令执行成功后才执行后面的命令
  • ||:或者,前一个命令执行失败后才执行后面的命令

4.2 文件测试

选项说明
-f文件是否为普通文件
-d文件是否为目录
-x文件是否有执行权限
-s文件大小大于0
-h/-L文件是否为软链接
[root@aliyun-ubuntu ~]# [ -f ./passwd.txt ] && echo file || echo 'not file'
file
[root@aliyun-ubuntu ~]# [ -d /etc/ ] && echo dir || echo 'not dir'
dir
[root@aliyun-ubuntu ~]# [ -d /etc/passwd ] && echo dir || echo 'not dir'
not dir

4.3 案例:书写脚本-检查文件类型

[root@aliyun-ubuntu /server/scripts]# cat check_type.sh 
#!/bin/bash
##############################################################
# File Name: check_type.sh
# Version: V1.0
# Author: SunKexu
# Organization: www.oldboyedu.com
# Description:test file type
##############################################################
export LANG=en.US_UTF-8# vars
file=$1
# command
# check param num
if [ $# -eq 0 ];thenecho "Usage:$0 file/dir"exit 1
fi
# soft link
if [ -h $file ];thenecho "$file is symbolic"exit 0
fi
# file
if [ -f $file ];thenif [ -x $file ];thenmode="has permisson"else mode="has not permission"fiif [ -s $file ];thensize="size not is 0"elsesize="size is 0"fiecho "${file} is file;permission:${mode};size:${size}"exit 0
fi
# dir
if [ -d $file ];thenecho "$file is directory"exit 0
fiecho "$file is other type file"
[root@aliyun-ubuntu /server/scripts]# bash check_type.sh
Usage:check_type.sh file/dir
[root@aliyun-ubuntu /server/scripts]# bash check_type.sh /sbin
/sbin is symbolic
[root@aliyun-ubuntu /server/scripts]# bash check_type.sh ./check_type.sh 
./check_type.sh is file;permission:has not permission;size:size not is 0
[root@aliyun-ubuntu /server/scripts]# bash check_type.sh /usr/   
/usr/ is directory
[root@aliyun-ubuntu /server/scripts]# bash check_type.sh ./test
./test is other type file

4.4 逻辑运算

逻辑运算符说明
-a并且
-o或者
取反

4.5 案例:书写脚本-检查服务是否正在运行或是开机自启动

[root@aliyun-ubuntu /server/scripts]# cat check_service2.sh 
#!/bin/bash
##############################################################
# File Name: check_service2.sh
# Version: V1.0
# Author: SunKexu
# Organization: www.oldboyedu.com
# Description:
############################################################### vars
name=$1
# command
if [ $# -eq 0 ];thenecho "Usage:$0 server name"exit 1
firunning=`systemctl is-active $name`
enable=`systemctl is-enabled $name`
if [ ${running}="active" -a ${enable}="enabled" ];thenecho "$name is running and enabled"
elseecho "$name is not running or enabled"
fi
[root@aliyun-ubuntu /server/scripts]# bash check_service2.sh
Usage:check_service2.sh server name
[root@aliyun-ubuntu /server/scripts]# bash check_service2.sh sshd
sshd is running and enabled

4.6 增强版条件测试命令:[[]]

[[ ]],比 [] 更强大,支持 &&||、正则匹配等

  • 正则匹配符号:=~,前后要有空格
[root@aliyun-ubuntu /server/scripts]# id=678
[root@aliyun-ubuntu /server/scripts]# [[ "$id" =~ [0-9]+ ]] && echo 1 || echo 2
1
[root@aliyun-ubuntu /server/scripts]# name=skx123
[root@aliyun-ubuntu /server/scripts]# [[ "$name" =~ [0-9]+ ]] && echo 1 || echo 2
1
[root@aliyun-ubuntu /server/scripts]# [[ "$name" =~ ^[0-9]+$ ]] && echo 1 || echo 2
2

4.7 面试题:[]与[[]]的区别?

基本条件测试命令:[]扩展条件测试命令:[[]]
无法使用正则可以使用正则
只能使用选项比价大小:-eq、-lt、-gt……可以使用选项,也能用字符:==、>=、<=……
逻辑符号只能用-a、-o、!逻辑符号能用选项,也能用&&、||

5. 字符串比较

符号说明
=“字符串” = “字符串”,注意加双引号和空格
!=判断不相等
-zzero,判断变量是否为空格
-nnot zero,判断变量是否不为空
[root@aliyun-ubuntu /server/scripts]# [ 123=123 ] && echo 1 || echo 2
1
[root@aliyun-ubuntu /server/scripts]# name="skx"
[root@aliyun-ubuntu /server/scripts]# [ ${name}="skx" ] && echo 1 || echo 2
1

5.1 案例:书写脚本-检查服务是否正在运行和开机自启动

[root@aliyun-ubuntu /server/scripts]# cat check_service.sh
#!/bin/bash
##############################################################
# File Name: check_service.sh
# Version: V1.0
# Author: SunKexu
# Organization: www.oldboyedu.com
# Description:check service status
##############################################################
export LANG=en.US_UTF-8# vars
service=$1# command
# check parameter num
if [ $# -eq 0 ];thenecho "Usage:$0 service name"exit 1
fi
# check running state
status_run=`systemctl is-active ${service}`
if [ ${status_run}="active" ];thenecho "${service} is running"
elseecho "${service} is not running"
fi# check enabled state
status_enabled=`systemctl is-enabled ${service}`
if [ ${status_enabled}="enabled" ];thenecho "${service} is enabled"
elseecho "${service} is not enabled"
fi
#####################################
if [ ${status_run}="active" -a ${status_enabled}="enabled" ];thenecho "$service is active and enabled"
fi
[root@aliyun-ubuntu /server/scripts]# bash check_service.sh sshd
sshd is running
sshd is enabled
sshd is active and enabled

6. 多分支:if、case

6.1 案例-统计根分区磁盘使用率,60-70输出警告,70-80输出需要处理,80-95输出需要及时处理,965以上输出立刻处理

[root@aliyun-ubuntu /server/scripts]# cat check_disk.sh
#!/bin/bash
##############################################################
# File Name: check_disk.sh
# Version: V1.0
# Author: SunKexu
# Organization: www.oldboyedu.com
# Description:
##############################################################export LANG=en.US_UTF-8# vars
usage=`df -h / |awk -F '[ %]' 'NR==2{print $(NF-2)}'`
# if
if [ $usage -gt 60 -a $usage -le 70 ];thenecho "Warning: Insufficient disk space ${usage}"
elif [ $usage -gt 70 -a $usage -le 80 ];thenecho "Warning: Insufficient disk space ${usage}"
elif [ $usage -gt 80 -a $usage -le 95 ];thenecho "Warning: Severe shortage of disk space ${usage}"
elif [ $usage -gt 95 ];thenecho "Warning: Disk space is about to run out ${usage}"
elseecho "Disk space is normal"
fi
[root@aliyun-ubuntu /server/scripts]# bash check_disk.sh
Disk space is normal

6.2 案例:判断系统类型

  • bash运行脚本是一个子shell程序,里面的变量仅在脚本中生效
  • source运行的脚本是在当前Shell环境,可以用来加载指定的变量
[root@aliyun-ubuntu /server/scripts]# cat check_os.sh
#!/bin/bash
##############################################################
# File Name: check_os.sh
# Version: V1.0
# Author: SunKexu
# Organization: www.oldboyedu.com
# Description:
##############################################################export LANG=en.US_UTF-8
# This file contains system version information
source /etc/os-release
# case
case "$ID" in kylin|rocky|centos) echo "$ID yum insatll package";;ubuntu|debian) echo "$ID apt install package";;*)echo "other system"esac[root@aliyun-ubuntu /server/scripts]# bash check_os.sh 
ubuntu apt install package

7. 踩坑记录

1. 条件测试时,变量要加上双引号

变量建议加引号

  • 如果变量可能为空或包含空格,必须加引号:
if [ "$var" = "hello" ]; then  # 正确
if [ $var = "hello" ]; then    # 如果 $var 为空,会报错

8. 思维导图

【金山文档】 思维导图 https://www.kdocs.cn/l/co3I7PtpTYQX


文章转载自:

http://bps4fGu7.ghcfx.cn
http://V99gDVre.ghcfx.cn
http://cragd42G.ghcfx.cn
http://6njscqbG.ghcfx.cn
http://TUeMtWCa.ghcfx.cn
http://Fj3sC77w.ghcfx.cn
http://zDBTQuNk.ghcfx.cn
http://WWXAB23V.ghcfx.cn
http://XPyRUiHV.ghcfx.cn
http://i52xBfp6.ghcfx.cn
http://22LfAdRy.ghcfx.cn
http://qf123cq1.ghcfx.cn
http://fUBeNfaF.ghcfx.cn
http://q81S533Z.ghcfx.cn
http://fENa8euL.ghcfx.cn
http://p98nqOnm.ghcfx.cn
http://12dxsvKM.ghcfx.cn
http://TScVnj9Q.ghcfx.cn
http://CM7AOM44.ghcfx.cn
http://GxjRzYYS.ghcfx.cn
http://FbHbGeQH.ghcfx.cn
http://moPYRT7o.ghcfx.cn
http://vC5iWgPl.ghcfx.cn
http://6YfHjmFv.ghcfx.cn
http://aiFIDrlG.ghcfx.cn
http://hNEcRAaJ.ghcfx.cn
http://LT0Sc90O.ghcfx.cn
http://qX3KKxSZ.ghcfx.cn
http://YjnF0exh.ghcfx.cn
http://yPMe3EHX.ghcfx.cn
http://www.dtcms.com/wzjs/765215.html

相关文章:

  • 给网站做rss济南网上房地产
  • 怎么做仿制网站成版年蝴蝶视频app免费
  • 旅游景区网站模板电商网站支付接口
  • 云霄网站建设苏州网站设计服务
  • 温州外贸网站建设网站的简单编程语言
  • dw进行网站建设包含哪些步骤做司考题的网站
  • 广州广告网站建设百度关键词刷搜索量
  • 做英文网站有哪些遵义网约车租车公司
  • 网站加地图网站的相关链接怎么做
  • 个人网站服务器推荐江苏专业做网站的公司
  • 关于解决网站 建设的请示兰州网站建设程序
  • 所有网站的分辨率常州网站运营公司
  • 软件网站开发教育行业网站怎么做
  • 建设系统网站怎样通过手机建网站
  • 怎么让网站被百度搜到电脑做系统哪个网站比较好
  • 南宁网站设计报价南通快速建设网站服务
  • 用什么软件做购物网站服务器租用国外
  • 网站界面一般用什么软件做广西公路建设协会网站
  • 网站建设 计入哪个科目公司部门团建活动策划方案
  • wordpress怎么登北京网站seo公司
  • 平度好的建设网站湖北做网站教程哪家好
  • 具有营销价值好的网站国际品牌的广州网页设计
  • 学做彩票网站有哪些html5网站开发实例
  • 建设微信商城网站制作深圳服务好的网站建设
  • 阿里巴巴做短视频网站海曙区建设局网站
  • 南昌网站推广电子商务网站如何设计
  • 专业的网站建设费用上海域名网站
  • 搭建门户网站网站建设介绍书
  • 免费无代码开发平台手机网站如何优化
  • zero的大型网站seo教程荷塘网站建设