S23.shell脚本每日一练

编程入门 行业动态 更新时间:2024-10-07 10:15:11

S23.shell<a href=https://www.elefans.com/category/jswz/34/1771291.html style=脚本每日一练"/>

S23.shell脚本每日一练

45.编写函数,实现打印绿色OK和红色FAILED

[root@centos8 ~]# vim ok_failed.sh
#!/bin/bash
#
#**********************************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2021-10-21
#FileName:      ok_failed.sh
#URL:           raymond.blog.csdn
#Description:   The test script
#Copyright (C): 2021 All rights reserved
#**********************************************************************************************
. /etc/init.d/functions
action "success!" true
action "failed!" false[root@centos8 ~]# bash ok_failed.sh 
success!                                                   [  OK  ]
failed!                                                    [FAILED]

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

[root@centos8 ~]# vim parameter.sh
#!/bin/bash
#
#**********************************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2021-10-21
#FileName:      parameter.sh
#URL:           raymond.blog.csdn
#Description:   The test script
#Copyright (C): 2021 All rights reserved
#**********************************************************************************************
args () {if [ $# -eq 0 ];then. /etc/init.d/functionsaction "fail...you must input a parameter" falsefi
}
args $1 [root@centos8 ~]# bash parameter.sh 
fail...you must input a parameter                          [FAILED][root@centos8 ~]# bash parameter.sh 0

更多推荐

S23.shell脚本每日一练

本文发布于:2024-02-13 10:05:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1758338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   shell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!