技术改变生活

博客园 首页 新随笔 联系 订阅 管理

随笔分类 -  shell

上一页 1 2 3 下一页

shell编写
摘要:for_null.sh内容: 1 #!/bin/bash 2 #for null line 3 #version 1.0 by feng 4 5 IFS=$'\n' 6 for i in `cat $1` 7 do 8 if [ ${#i} -eq 0 ];then 9 echo "the line 阅读全文
posted @ 2020-04-25 23:54 小阿峰 阅读(646) 评论(0) 推荐(0)

摘要:vim while_create_user.sh 1 #!/usr/bin/bash 2 3 #while create user 4 5 #v1.0 by xfeng 6 7 while read line 8 9 do 10 11 if [ ${#line} -eq 0 ];then #变量的字 阅读全文
posted @ 2020-04-25 22:10 小阿峰 阅读(366) 评论(0) 推荐(0)

摘要:1、创建用户 useradd01.sh 1 #!/bin/bash 2 3 ############################### 4 5 #useradd # 6 7 #v1.0 by userf 2019.08.0 # 8 9 ############################## 阅读全文
posted @ 2020-04-25 22:09 小阿峰 阅读(137) 评论(0) 推荐(0)

摘要:cat yum_if.sh 1 #!/bin/bash 2 3 4 #if for many branches yum 5 #version 1 by feng 6 7 yum_server=192.168.0.117 8 Os_version=$(cat /etc/redhat-release | 阅读全文
posted @ 2020-04-25 14:43 小阿峰 阅读(188) 评论(0) 推荐(0)

摘要:jumpserver原理图 前端到跳板机jumpserver的alice用户密码,和jumpserver到后端服务器的密码可以不同。用户可以通过jumpserver登陆后端服务器但是不能登陆到jumpserver服务器本身,需要在jumpserver服务器上设置登陆用户登陆后的初始化环境中定义登陆到 阅读全文
posted @ 2020-04-24 23:59 小阿峰 阅读(736) 评论(0) 推荐(0)

该文被密码保护。
posted @ 2020-04-24 22:52 小阿峰 阅读(3) 评论(0) 推荐(0)

摘要:变量自增语法:a=a+1 字符串拼接语法:a=$0" "a shell的终端打印echo hello worldecho "hello world"echo 'hello world'echo "hello world \!"echo 'hello world !'使用不带引号的echo时,没法在所 阅读全文
posted @ 2020-04-08 17:36 小阿峰 阅读(164) 评论(0) 推荐(0)

摘要:shell格式的if语句: [root@www file_test]# cat if.sh #!/bin/bash#if testif [ $# -eq 0 ];then exitfiif [ $1 -eq 1 ];then echo "the num is : abc"elif [ $1 -gt 阅读全文
posted @ 2020-04-08 15:09 小阿峰 阅读(303) 评论(0) 推荐(0)

摘要:数组借助索引将多个独立的数据存储为一个集合,是shell脚本非常重要的组成部分。 [root@localhost linshi]# cat passwd3root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2 阅读全文
posted @ 2020-04-04 13:07 小阿峰 阅读(262) 评论(0) 推荐(0)

摘要:#将passwd文件每行重复打印10遍;while循环,当i>10时,结束循环。 [root@localhost linshi]# awk '{i=1;while(i<=10){print $0;i++}}' passwd root:x:0:0:root:/root:/bin/bashroot:x: 阅读全文
posted @ 2020-02-23 20:39 小阿峰 阅读(248) 评论(0) 推荐(0)

摘要:函数的定义 函数名称() { 执行的代码块 } function 函数名 { 执行的代码块 } 函数需要先定义,然后才能调用;调用函数时,只需要输入函数名即可;函数可以多次反复调用。 函数中定义的变量和shell中的变量不是一回事;函数中定义的变量,需要在调用函数时赋值或引用。函数中的变量和shel 阅读全文
posted @ 2020-01-31 21:21 小阿峰 阅读(827) 评论(0) 推荐(1)

摘要:数组是特殊的变量,普通变量可以支持切片 a=sum_abc.mail.cn echo ${a:5:3} abc 普通数组只能使用整数做为数组索引,关联数组可以使用字符串做为数组索引 普通数组 apples=(linux shell wps fox wp) linux shell wps fox wp 阅读全文
posted @ 2020-01-31 11:30 小阿峰 阅读(156) 评论(0) 推荐(0)

摘要:for while 表是条件为真时执行循环体中的内容;until表是条件为假时,执行循环体中的内容。 for_while_until_ping.sh #!/usr/bin/bash #for while until ping #v1 by xfeng 2019.02.30 for i in {2.. 阅读全文
posted @ 2020-01-30 20:19 小阿峰 阅读(185) 评论(0) 推荐(0)

摘要:until与while对比 while语句结构 while 条件测试 do 循环体 done 当条件测试成立(条件测试为真),执行循环体 until语句结构 until 条件测试 do 循环体 done 当条件测试不成立(条件测试为假),执行循环体 while适合写下线的例子;until适合写上线的 阅读全文
posted @ 2020-01-30 20:02 小阿峰 阅读(547) 评论(0) 推荐(0)

摘要:linux中shell执行注意细节 语法: bash -n a.sh #检测bash语法是否有错 bash -vx a.sh #查看a.sh的执行过程,+代表已经执行的动作 grep命令的语法: grep [OPTIONS] PATTERN [FILE...] 例如: [root@a ~]# sed 阅读全文
posted @ 2020-01-26 20:07 小阿峰 阅读(249) 评论(0) 推荐(0)

摘要:Linux中常用的命令 #nl filename 使用nl命令打印文件内容并显示行号 #sed '/nw/,$d' filename 使用sed命令删除匹配nw至最后一行的内容 #cat filename | sed '/字段信息/,$!d' 使用sed的!取反,只打印匹配到的信息至最后一行的内容 阅读全文
posted @ 2019-10-22 22:23 小阿峰 阅读(336) 评论(0) 推荐(0)

摘要:常用命令实践 [root@b ~]# cat c.txt1.1.1.12.2.2.23.3.3.34.4.4.4 [root@b ~]# cat c.txt |sed 's/^/& /' &作用是代替前面需要替换旧的内容,这里指^。而^有指代以某某开头。 1.1.1.1 2.2.2.2 3.3.3. 阅读全文
posted @ 2019-05-24 10:31 小阿峰 阅读(358) 评论(0) 推荐(0)

摘要:[root@a ~]#cat break.sh #!/bin/bash while : #其中“:”表示while循环的条件永远为真的意思 do read -p "Enter a number [1-5]: " num case $num in 1|2|3|4|5) echo "It's OK" ; 阅读全文
posted @ 2019-05-13 18:15 小阿峰 阅读(4184) 评论(0) 推荐(0)

摘要:shell函数,完成特定功能的代码片段(代码模块化)。函数必须先定义,然后才能使用。 shell函数的定义: 方法一: 函数名() { 函数要实现的功能代码 } 方法二:function 函数名 { 函数要实现的功能代码 } shell函数的调用: 函数名 函数名 参数1 参数2 [root@a ~ 阅读全文
posted @ 2019-05-13 17:47 小阿峰 阅读(677) 评论(0) 推荐(0)

摘要:url=www.computergame.com #定义一个变量 echo ${#url} #变量字符串数量统计 20 echo ${url:0:10} #变量中字符串的截取,变量的切片操作 www.comput echo ${url:5} #变量切片操作,不指定切片数量,默认取所有 compute 阅读全文
posted @ 2019-05-10 11:14 小阿峰 阅读(289) 评论(0) 推荐(0)

上一页 1 2 3 下一页