C程序返回codeS和&功放;&安培; bash的符号? [英] C program return codes and && bash symbol?

查看:139
本文介绍了C程序返回codeS和&功放;&安培; bash的符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bash中,我们可以用&功放;&安培;运营商执行两个指令。例如:

In bash, we can use the && operator to execute two commands. For example:

./foo && ./bar

将首先执行,且仅当foo是成功,这将执行。但是,当你考虑到C程序,按照惯例,返回这似乎有悖常理0或退出(0)成功完成,运行反直觉的行为时在&放大器;&安培; 运营商。 (因为在大多数语言中,0被认为是一个falsey,从而会从停止执行第二条语句。)我缺少什么?

Will first execute foo, and only if foo is "successful", it will then execute bar. However, this seems counter-intuitive when you consider that C programs, by convention, return 0 or exit(0) upon successful completion, which runs counter-intuitive to the behavior of the && operator. (Since in most languages, 0 is considered to be a 'falsey', and thus would stop the second statement from executing.) What am I missing?

推荐答案

您不会错过任何东西。你一定要记住,真正不在外壳基本概念。 成功失败

You're not missing anything. You just have to keep in mind that true and false aren't fundamental concepts in the shell. success and failure are.

这篇关于C程序返回codeS和&功放;&安培; bash的符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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