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

泷羽sec-星河飞雪-shell-5

免责声明

学习视频来自 B 站up主泷羽sec,如涉及侵权马上删除文章。

笔记的只是方便各位师傅学习知识,以下代码、网站只涉及学习内容,其他的都与本人无关,切莫逾越法律红线,否则后果自负。

泷羽sec官网:https://longyusec.com/

泷羽sec B站地址:https://space.bilibili.com/350329294

泷羽sec帮会:https://wiki.freebuf.com/front/societyFront?invitation_code=5a2005d9&society_id=239&source_data=2

文章目录

    • 流程控制
      • `if`
      • `if else`
      • `if elif else`
    • 循环
      • for

流程控制

if

if condition
then
    command1 
    command2
    ...
    commandN 
fi

写成一行的话是这样,适用于终端命令行

if [ $(ps -ef | grep -c "bash") -gt 1 ]; then echo "true"; fi

  1. $(...):这是命令替换的语法,它会执行括号内的命令,并将输出替换到当前位置。因此,$(ps -ef | grep -c "ssh")会执行ps -efgrep -c "ssh"的组合命令,并将输出(即包含"ssh"的进程数)替换到if语句的条件判断部分

  2. if [...]; then ...; fi:这是if语句的语法,用于根据条件执行不同的命令。如果条件([...]内的表达式)为真,则执行then后面的命令;否则,不执行

末尾的 fi 就是 if 倒过来拼写

if else

if condition
then
    command1 
    command2
    ...
    commandN
else
    command
fi

if elif else

if condition1
then
    command1
elif condition2 
then 
    command2
else
    commandN
fi

需要注意的是,在if else[……]判断中,大于用-gt,小于用-lt

但如果使用((……))做判断的话,大于小于则可以直接用< >

循环

for

for var in item1 item2 ... itemN
do
    command1
    command2
    ...
    commandN
done

写成一行是这样

for var in item1 item2 ... itemN; do command1; command2… done;

当变量值在列表里,for 循环即执行一次所有命令,使用变量名获取列表中的当前取值。

命令可为任何有效的 shell 命令和语句。in 列表可以包含替换、字符串和文件名。

in列表是可选的,如果不用它,for循环使用命令行的位置参数。

for i in 1 2 3 4 5
do 
	echo the var is $i
done

输出结果是

the var is 1
the var is 2
the var is 3
the var is 4
the var is 5

is $i
done


输出结果是

```shell
the var is 1
the var is 2
the var is 3
the var is 4
the var is 5

http://www.kler.cn/a/408052.html

相关文章:

  • 钉钉免登录接口
  • Nginx正向代理處理HTTPS請求詳解
  • 【系统架构设计师】真题论文: 论软件可靠性设计技术的应用(包括解题思路和素材)
  • java excel 导入各种踩坑
  • el-table设置轻提示:show-overflow-tooltip=“true“,改变轻提示宽度
  • Java零拷贝二步曲——Linux 中的零拷贝技术
  • 3、.Net UI库:EASkins - 开源项目研究文章
  • 开源框架重构说明
  • C0030.Clion中运行提示Process finished with exit code -1073741515 (0xC0000135)解决办法
  • C++特殊类设计(不能被拷贝的类、只能在堆上创建对象的类、不能被继承的类、单例模式)
  • Tomcat的工作模式是什么?
  • 【DP】个人练习-Leetcode-2019. The Score of Students Solving Math Expression
  • React项目设置不同模式(开发development与生产production)——cross-env与env-cmd详解
  • TCP socket api详解
  • 深入理解 DevOps:从理念到实践
  • QML TableView(Qt_6_5_3_MinGW_64)
  • 【解决】Unity TMPro字体中文显示错误/不全问题
  • 【分布式锁解决超卖问题】setnx实现
  • Linux 的CENTOS7扩容3T空间
  • 基于SpringBoot+Vue的高校社团管理系统