linux下action使用详解

linux下action方法这个网上资料较少,这个方法命令的作用是显示ok或者failed,我们可以写shell脚本的时候进行美化输出

下面就是一个安装结果输出的例子

Install successfly !                                                 [  OK  ]
Install failed !                                                     [FAILED]

我们的脚本例子是

#!/bin/bash
. /etc/rc.d/init.d/functions
if [ ? -eq 0 ]
then
    action "Install successfly !"   /bin/true
else
    action "Install failed !"   /bin/true
fi

我们再来看看该方法命令原型,在/etc/rc.d/init.d/functions函数中

# Run some action. Log its output.
action() {
  local STRING rc

  STRING=$1
  echo -n "$STRING "
  shift
  "$@" && success $"$STRING" || failure $"$STRING"
  rc=$?
  echo
  return $rc
}


内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/275.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。