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.net
#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.net
#Description:   The test script
#Copyright (C): 2021 All rights reserved
#**********************************************************************************************
args () {
    
    
    if [ $# -eq 0 ];then
    . /etc/init.d/functions
    action "fail...you must input a parameter" false
    fi
}
args $1 

[root@centos8 ~]# bash parameter.sh 
fail...you must input a parameter                          [FAILED]

[root@centos8 ~]# bash parameter.sh 0

猜你喜欢

转载自blog.csdn.net/qq_25599925/article/details/126772707