技术改变生活

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

2020年10月5日 #

摘要: awk是文本处理工具,功能小结如下: 1、条件表达式 [root@centos17 shell]# awk -F: '$3>1&&$3<3{print $0}' /etc/passwd daemon:x:2:2:daemon:/sbin:/sbin/nologin [root@centos17 sh 阅读全文
posted @ 2020-10-05 20:06 小阿峰 阅读(213) 评论(0) 推荐(0) 编辑

摘要: 阶乘计算 版本一: [root@centos17 shell]# sh -v factorial.sh #!/bin/bash factorial() { factorial1=1 for((i=1;i<=5;i++));do factorial1=$((factorial1*i)) done ec 阅读全文
posted @ 2020-10-05 19:28 小阿峰 阅读(145) 评论(0) 推荐(0) 编辑

摘要: #!/bin/bash 官方推荐写法 #/usr/bin/env bash 最好的写法 #!/usr/bin/bash #!/bin/sh #!/usr/sh 后三种写法,根据不同的linux版本,路径会有所改变导致程序无法识别。可以使用#/usr/bin/env bash来替代。 阅读全文
posted @ 2020-10-05 18:56 小阿峰 阅读(232) 评论(0) 推荐(0) 编辑

摘要: 关联数组 [root@centos17 shell]# cat shells_count.sh #!/bin/bash #login shell counts declare -A shells while read line do type=`echo $line|awk -F":" '{prin 阅读全文
posted @ 2020-10-05 11:09 小阿峰 阅读(251) 评论(0) 推荐(0) 编辑