加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

这个bash语句中的想法是什么(命令|| true)?

发布时间:2020-12-15 22:39:47 所属栏目:安全 来源:网络整理
导读:我在互联网上看到了以下bash语句: PYTHON_BIN_PATH=$(which python || which python3 || true) 我明白,如果哪个python失败了,那么哪个python3会被执行,但我不明白条件结束时的真实目的.任何的想法? 解决方法 试试跑:(注意bla) which python_bla || which p
我在互联网上看到了以下bash语句:

PYTHON_BIN_PATH=$(which python || which python3 || true)

我明白,如果哪个python失败了,那么哪个python3会被执行,但我不明白条件结束时的真实目的.任何的想法?

解决方法

试试跑:(注意bla)

which python_bla || which python3_bla_bla || true
echo $?
0

你会得到RC = 0.这意味着它是一个成功进入下一个命令的构造.在这里我们知道python_bla或python3_bla_bla不存在,但仍然命令给出了rc = 0
示例:检查以下三个命令的RC,我已将date命令的拼写更改为不正确但true为导致RC保持为0.

date;echo $?
Thu Nov  9 01:40:44 CST 2017
0
datea;echo $?
If 'datea' is not a typo you can use command-not-found to lookup the package that contains it,like this:
    cnf datea
127
datea||true;echo $?
If 'datea' is not a typo you can use command-not-found to lookup the package that contains it,like this:
    cnf datea
0

注意:您还可以使用:operator而不是true来获得相同的结果.示例:

command || :

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读