shell
文章平均质量分 65
LiLittleCat
这个作者很懒,什么都没留下…
展开
-
Shell 脚本中判断字符串非空
前言Shell 脚本中经常用到字符串,对字符串是否为空的判断很关键。正文在 Shell 中利用 -n 来判断字符串是否非空。例子:if [[ str1 = str2 ]] # 当字符串 str1 和 str2 有相同内容、长度时为真if [[ str1 != str2 ]] # 当字符串 str1 和 str2 不等时为真if [[ -n str1 ]] # 当字符串 str1 的长度大于 0 (非空)时为真 if [[ -z str1 ]] # 当字符串 st原创 2021-09-08 21:23:01 · 32776 阅读 · 3 评论 -
CentOS 7 下 vim 编辑文件显示行号
修改 Vim 配置文件 /etc/vimrcvim /etc/vimrc配置文件中增加如下配置并保存set nu或set number使配置文件生效source /etcc/vimrc原创 2020-10-23 13:48:54 · 560 阅读 · 0 评论 -
Python编写部署脚本总结
文章目录Python笔记一、python基础1.1 变量1.2 if语句1.3 while语句1.4 for语句与range函数1.5 输入输出1.6 列表1.7 元组1.8 字典1.10 文件读写1.11 类1.12 异常二、python脚本2.1 python脚本执行shell命令2.2 python读取json文件2.3 python访问pg数据库2.4 python写日志文件三、python进阶3.1 生成器3.2 高阶函数3.3 匿名函数3.4 装饰器Python笔记由于shell脚本的书写和原创 2020-07-23 19:04:20 · 1113 阅读 · 0 评论 -
linux使用sh执行脚本中有source命令时提示找不到文件
文章目录问题原因分析解决方法问题shell脚本a.sh如下:#!/bin/bashcd /home/if [ -f b.sh ];thensource b.shfi使用sh命令执行a.sh:[root@localhost osc]# sh a.sh a.sh: line 4: source: b.sh: file not found原因分析source 命令找filename是在当前Shell环境中从文件名读取并执行命令,如果filename不包含斜杠,则使用PATH中的文件名查原创 2020-07-06 16:20:21 · 10388 阅读 · 2 评论 -
shell脚本实现读取yaml文件中的数组属性
目的该脚本用于读取yaml文件中的数组属性,如IP列表:ips: - 127.0.0.1 - 127.0.0.2 - 127.0.0.3脚本function read_array(){ flag=0 # 逐行读取内容 cat $1 | while read LINE do if [ $flag == 0 ];then # 属性开始标志 ips if [ "$(echo $LINE | gr原创 2020-07-01 16:45:13 · 4756 阅读 · 1 评论