码迷,mamicode.com
首页 > 其他好文 > 详细

/bin/true /bin/false作用

时间:2020-03-12 19:03:00      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:null   linux系统   usr   code   server   run   opp   dev   程序   

/bin/true /bin/false是linux系统自带的程序
/bin/true返回的是 0
/bin/false返回的是 1 (也有说是非0值)

一般用于自写脚本根据自己的逻辑来设置 $? 的值


例子

/bin/true
echo $?
#结果
0

/bin/false
echo $?
#结果
1

使用说明

#两个function,这两个函数引用了 /etc/init.d/functions ,使用了action函数
#
[server]-[root@arrow ~]$action "test" /bin/true ;echo $?
test                                                       [  OK  ]
0

[server]-[root@arrow ~]$action "test" /bin/false ;echo $?
test                                                       [  OK  ]
1

#注意下面实际echo $? 返回的 0  是action的结果
#上面的两条返回的是true false的结果
[server]-[root@arrow ~]$action "test"  ;echo $?
test                                                       [  OK  ]
0

------------------------------------------------------------------------------------------------------
Start_Nginx(){
if [ -f $pidfile ];then
        echo "Nginx is running"
else
        /usr/local/nginx/sbin/nginx &>/dev/null
        action "Nginx is Started" /bin/true
fi
}
###########################################################
Stop_Nginx(){
if [ -f $pidfile ];then
        /usr/local/nginx/sbin/nginx -s stop &>/dev/null
        action "Nginx is Stopped" /bin/true
else
        action "Nginx is Stopped" /bin/false
fi
}

/bin/true /bin/false作用

标签:null   linux系统   usr   code   server   run   opp   dev   程序   

原文地址:https://blog.51cto.com/14316149/2477633

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!