" echo ||的用途是什么真的"? [英] What is the use of "echo || true"?

查看:81
本文介绍了" echo ||的用途是什么真的"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会有人想要像echo "something" || true这样的代码?

Why would anyone want to have a code like echo "something" || true ?

我在Ubuntu 14.04的/lib/lsb/init-functions的第92行发现了这种用法:

I found such a usage on line 92 of /lib/lsb/init-functions on an Ubuntu 14.04:

echo "$pid" || true

我了解||代表OR.但是我找不到一种使echo产生除零以外的任何形式的退出代码的方法.即使有,谁在乎呢?

I understand that || stands for OR. But I could not find a way to make echo produce any sort of exit code other than zero. And even if it does, who cares?

我的意思是,使用前缀|| true确保退出代码始终为0.因此,如果双管道的左侧产生的值与0不同,则将执行true并导致整行产生0

I mean, using the prefix || true ensures that the exit code is always 0. So if the left-hand side of the double pipe yields anything different from 0, true will be executed and cause the whole line to yield 0.

为什么偏执狂带有退出代码的简单回声?是否有任何检查/lib/lsb/init-functions上的每一行是否都成功完成?

Why the paranoia with the exit code of a simple echo? Is there anything checking if every single line on /lib/lsb/init-functions finishes with success?

推荐答案

为什么偏执狂带有退出代码

Why the paranoia with the exit code

我相信这是为了避免脚本因可能的使用而退出:

I believe it is to avoid script exiting due to possible use of:

set -e

在脚本开始时否则会导致脚本退出.

at start of the script which would have caused script to exit otherwise.

这篇关于" echo ||的用途是什么真的"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆