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

互助县公司网站建设百度推广一级代理商名单

互助县公司网站建设,百度推广一级代理商名单,北京网站建设网,web前端开发的意义题目 提示:没有基础请先看看基础部分的讲解,否则看不懂 1,编写函数,实现判断是否无位置参数,如无参数,提示错误 代码: #bash/bin function a() {b$# #判断传入的参数个数 # echo $b…

题目

提示:没有基础请先看看基础部分的讲解,否则看不懂

1,编写函数,实现判断是否无位置参数,如无参数,提示错误

代码:

#bash/bin
function a() {b=$#   #判断传入的参数个数
#       echo $bif [ $b -eq 0 ]   # 看参数个数是不是等于0 thenecho "no"elseecho "yes"fi
}
a

1,当不传入参数时,结果为:

no

2,当传入参数时,结果为:

yes

2,编写函数实现两个数字做为参数,返回最大值

代码

function a() {    # 定义函数num1=$1   # 获取第一个参数
#       echo "num1:$num1"num2=$2
#       echo "num2:$num2"if [ $num1 -gt $num2 ]     # 2个参数进行比较thenecho "$num1"    # 返回第一个参数elseecho "$num2"   # 返回得第二个参数fi
}
c=$(a 200 300)     # 传入2个参数,并且将返回值赋值给c
echo "the $c is more big"

运行输出结果:

[root@localhost ~]# bash functiontest.sh 
the num1:200
num2:300
300 is more big

3,编写函数,实现两个整数位参数,计算加减乘除

代码

a(){one=$1two=$2echo  "$one + $two = `expr $one + $two`"echo  "$one - $two = `expr $one - $two`"echo  "$one * $two = `expr $one \* $two`"echo  "$one / $two = `expr $one / $two`"printf  "$one / $two = `expr $one / $two`\n"}
a 2 3

运行结果

[root@localhost ~]# bash functiontest.sh 
2 + 3 = 5
2 - 3 = -1
2 * 3 = 6
2 / 3 = 0
2 / 3 = 0

4、将/etc/shadow文件的每一行作为元数赋值给数组

代码

function a(){a=`wc -l /etc/shadow | cut -d" " -f1`   # 将目标文件进行剪切,提取需要的数据,这里代表数据个数
for i in `seq $a`
dob=`expr $i - 1`     # 数组下标arr[$b]=`awk 'NR=='$i'{print}' /etc/shadow`    # 将对应的哪一行数据放入到数组
done
}
a
echo ${arr[0]}     # 打印数组的第一个元素
echo ${arr[1]}    #第二个
echo ${arr[2]}
echo ${arr[3]}

以上的结果显示为: 结果的验证可以用cat 命令对目标文件进行对比

[root@localhost ~]# bash functiontest.sh 
root:$6$SqQF33Q5poRxzqNJ$mAZ7EJuymCGVS6HxSAinq4danhF48kUbkyg/Kck3VJ8mIO5tDJlrsbQ04.aXbUb63rif82rIR/Xuatvcdj6Bp1::0:99999:7:::
bin:*:19121:0:99999:7:::
daemon:*:19121:0:99999:7:::
adm:*:19121:0:99999:7:::

5,使用关联数组统计文件/etc/passwd中各个用户的shell类型

代码

function a(){read -p "which user's shell type that you want find?:" shell_type  # 提示加读取输入的变量declare -A arry    # 必须声明关联数组l=`wc -l /etc/passwd | cut -d " " -f1`   # 计算数据的条数for i in `seq $l`do
#               ass-arry[`expr $i - 0`] index=`cat /etc/passwd | awk 'BEGIN{FS=":"}{print $1}' | awk  'NR=='$i'{print}'`  # 关联数组的下标#       echo "index $index"declare -A arryarry["$index"]=`cat /etc/passwd | awk 'BEGIN{FS=":"}{print $7}' | awk 'NR=='$i'{print}'`  # 关联数组的值doneecho "the user $shell_type's shell type is ${arry[$shell_type]}"   # 格式化输出
}
a

运行的结果:

[root@localhost ~]# bash functiontest.sh 
which user's shell type that you want find?:fu
the user fu's shell type is /bin/bash[root@localhost ~]# bash functiontest.sh 
which user's shell type that you want find?:root
the user root's shell type is /bin/bash[root@localhost ~]# bash functiontest.sh 
which user's shell type that you want find?:bin
the user bin's shell type is /sbin/nologin

6,使用关联数组按扩展名统计指定目录中文件的数量

代码

function a() {read -p "input a file path (absolute):(such as input /etc/)>" path  # 输入路径read -p "which type of file are you count ?:(such as input txt or sh ...)>" type1  # 输入文件类型a=`ls -l $path | awk '{print $9}' | grep '^[^$]' | awk 'BEGIN{FS="."}{print $2}'`   # 看有几个文件有后缀名declare -A arrfor i in $ado#         echo "file type: $i"arr["$i"]=`expr ${arr["$i"]} + 1`   # 对文件类型计数表示该类型文件个数doneecho "the file of type $type1 have ${arr[$type1]}"
}
a

运行结果如下:结果的验证可以用自己数

[root@localhost ~]# bash functiontest.sh 
input a file path (absolute):(such as input /etc/)>/etc/
which type of file are you count ?:(such as input txt or sh ...)>conf
the file of type conf have 36[root@localhost ~]# bash functiontest.sh 
input a file path (absolute):(such as input /etc/)>/etc/
which type of file are you count ?:(such as input txt or sh ...)>d
the file of type d have 24

7,编写函数 ,判断是否有参数,存在为Ok,不存在为FAILED,要求绿色OK和红色FAILED

代码:

function a() {b=$#
##      echo $bif [ $b -eq 0 ]thenecho -e "\e[31m failde \e[0m";elseecho -e "\e[32m ok \e[0m";fi
}
a 1
http://www.15wanjia.com/news/23014.html

相关文章:

  • 做网站需要什么部门批准广东深圳疫情最新消息今天
  • 空间商网站ip被攻击后换ip收录提交入口网址
  • 怎么做网站seo优化信息发布平台推广有哪些
  • 有没有专门做一件代发的网站创建网站怎么创
  • 成都住房和城乡建设局网站投放广告
  • wordpress登录wp-admin网站排名在线优化工具
  • 做代购可以在哪些网站上免费网络营销推广软件
  • 做汽车的网站百度seo网站优化服务
  • wordpress epub重庆seo顾问服务
  • 网站开发宣传图片明星百度指数排名
  • 慈溪建设银行支行网站百度不收录网站
  • 做网站服务器是什么短视频营销常用平台有
  • 做网站要有策划么市场营销策略有哪些
  • 做seo学网站网络推广外包想手机蛙软件
  • 福永网站制作seo推广关键词公司
  • 淮安做网站.哪家网络公司好收录优美图片topit
  • 网站备案去哪里办理百度seo推广怎么做
  • 网站建设课的感想全文搜索引擎有哪些
  • 模板网站的优缺点爱站网的关键词是怎么来的
  • 邯山专业做网站安卓优化大师下载安装
  • wordpress整站搬家教程百度竞价登录
  • 无货源开店已确认违法关键词怎样做优化排名
  • flash网站cms网站建设与营销经验
  • 帮人注册网站 做app网站网络营销推广
  • 如何搞好网站建设网站制作报价
  • 网站建设后运维合同友情链接赚钱
  • 网站建设怎么搞宁波seo怎么推广
  • 网站开发工作内容无锡百度推广代理商
  • 游戏网站建设内容福州360手机端seo
  • 常德哪里有做网站元搜索引擎有哪些